package cn.qayy.controller;

import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

import javax.annotation.Resource;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import javax.servlet.http.HttpSession;

import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;

import com.alibaba.fastjson.JSONObject;

import cn.qayy.dto.Country1000;
import cn.qayy.dto.FeiYong;
import cn.qayy.dto.GoodFriend1000;
import cn.qayy.dto.KdbNssLogClientPolicyItem;
import cn.qayy.dto.MgrsProvinces;
import cn.qayy.dto.MonthPVG1000View;
import cn.qayy.dto.Plans;
import cn.qayy.dto.PlansView;
import cn.qayy.dto.ProductProvinceData;
import cn.qayy.dto.ProductProvinceView;
import cn.qayy.dto.ProductSpaceData;
import cn.qayy.dto.ProductSpaceView;
import cn.qayy.dto.QudaoProvinceData;
import cn.qayy.dto.QudaoProvinceView;
import cn.qayy.dto.QudaoSpaceData;
import cn.qayy.dto.QudaoSpaceView;
import cn.qayy.dto.ReportPlans;
import cn.qayy.dto.ReportPlansJ;
import cn.qayy.dto.ReportPlansQ;
import cn.qayy.dto.ReportPlansTerminal;
import cn.qayy.dto.ReportPlansZ;
import cn.qayy.dto.TPPScountData;
import cn.qayy.dto.TPPScountView;
import cn.qayy.dto.Terminal1000;
import cn.qayy.dto.TerminalPlans;
import cn.qayy.po.User;
import cn.qayy.service.IPlansService;
import cn.qayy.utils.ExcelUtils;
import cn.qayy.utils.JsonResult;
import cn.qayy.utils.ResonseUtils;

/**
 * @author jobs1127
 */
@Controller
@RequestMapping(value = "/plans")
public class PlansController {
    //注入service
    @Resource(name = "plansServiceImpl")
    private IPlansService plansService = null;
    //流向下载需要的表头
    private final static String[] plansTitle = new String[]{
            "年", "月",  "条线", "经理","大区", "片区",
            "省份","地市", "区县",
            "日期","行为", "出货甲方", "入货乙方","QS名","品种", "包装",
            "数量","销售折量","生产折量","批号", "分部", "渠道", "级别",
            "客户","代表", "协议id", "协议状态",
            "收款人","开户行", "银行账号",
            "票据方案","模式","结算方式", "中标价", "配送率","开票价",
            "标准测算价", "协议测算价","1服务费(基础)", "1金额", "1状态",
            "3服务费(财务)", "3金额", "3状态","4服务费（达标）", "4金额", "4状态","总费用",
            "5开发奖励","5金额","5状态","业务员开发奖励","业务员奖励金额","业务员奖励状态",
            "中标金额","开票金额",
            "片区提成人","大区提成人","区域主管","贡献提成人",
            "片区存量来源", "片区存量提成","片区增量来源","片区增量提成","片区晚交流向扣减","片区晚交流向提成",
            "高阶来源", "高阶提成","贡献来源","贡献提成","主管存量来源","主管存量提成",
            "主管增量来源","主管增量提成",
            "大区存量来源","大区存量提成","大区增量来源","大区增量提成","大区晚交流向扣减","大区晚交流向提成",
            "提成状态","提成备注",
            "重点终端标识","好伙伴标识",
            "晚交流向标识","真自然流向标识","不合规流向标识",
            "录入人员","流向备注","录入日期","虚拟成本", "流向ID"};
    
    //流向下载需要的表头
    private final static String[] plansTitle_Q = new String[]{
    		"年", "月",  "条线", "经理","大区", "片区",
    		"省份","地市", "区县",
    		"日期","行为", "出货甲方", "入货乙方","QS名","品种", "包装",
    		"数量","销售折量","生产折量","批号", "分部", "渠道", "终端级别",
    		"客户","客户级别","代表", "协议id", "协议状态",
    		"收款人","开户行", "银行账号",
    		"票据方案","模式","结算方式", "中标价", "配送率","开票价",
    		"标准测算价", "协议测算价","1服务费(基础)", "1金额", "1状态",
    		"3服务费(财务)", "3金额", "3状态","4服务费（达标）", "4金额", "4状态","总费用",
    		"5开发奖励","5金额","5状态","业务员开发奖励","业务员奖励金额","业务员奖励状态",
    		"中标金额","开票金额",
    		"片区提成人","大区提成人","区域主管","贡献提成人",
    		"片区存量来源", "片区存量提成","片区增量来源","片区增量提成","片区晚交流向扣减","片区晚交流向提成",
    		"高阶来源", "高阶提成","贡献来源","贡献提成","主管存量来源","主管存量提成",
    		"主管增量来源","主管增量提成",
    		"大区存量来源","大区存量提成","大区增量来源","大区增量提成","大区晚交流向扣减","大区晚交流向提成",
    		"提成状态","提成备注",
    		"重点终端标识","好伙伴标识",
    		"晚交流向标识","真自然流向标识","不合规流向标识",
    		"录入人员","流向备注","录入日期","虚拟成本", "流向ID"};
    //流向下载需要的表头
    private final static String[] plansTitle_Z = new String[]{
    		"年", "月",  "条线", "经理","大区", "片区",
    		"省份","地市", "区县",
    		"日期","行为", "出货甲方", "入货乙方","QS名","品种", "包装",
    		"数量","销售折量","生产折量","批号", "分部", "渠道", "终端级别",
    		"客户","客户级别","代表", "协议id", "协议状态",
    		"收款人","开户行", "银行账号",
    		"票据方案","模式","结算方式", "中标价", "配送率","开票价",
    		"标准测算价", "协议测算价","1服务费(基础)", "1金额", "1状态",
    		"3服务费(财务)", "3金额", "3状态","4服务费（达标）", "4金额", "4状态","总费用",
    		"5开发奖励","5金额","5状态","业务员开发奖励","业务员奖励金额","业务员奖励状态",
    		"中标金额","开票金额",
    		"重点终端标识","好伙伴标识",
    		"晚交流向标识","真自然流向标识","不合规流向标识",
    		"录入人员","流向备注","录入日期","虚拟成本", "流向ID"};
    
    //流向下载需要的表头 简
    private final static String[] plansTitle_J = new String[]{
    		"年", "月",  "条线", "经理","大区", "片区",
    		"省份","地市", "区县",
    		"日期","行为", "出货甲方", "入货乙方","QS名","品种", "包装",
    		"数量","销售折量","分部", "渠道", "终端级别",
    		"客户","客户级别",
    		"模式","流向备注","流向ID"};


    //协议下载需要的表头
    private final static String[] policysTitle = new String[]{
    	     "条线", "经理","省份","地市", "品种",
            "包装","客户", "代表", "入货乙方","协议备注","渠道", "模式", "结算方式",
            "中标价","开票价","协议状态", "1服务费(基础)", "3服务费(财务)","4服务费(达标)",
            "标准测算价","协议测算价","资金成本","票据方案",
            "基础政策","开发奖励月数", "协议标杆", "协议开始时间","协议结束时间",
            "收款人", "开户行", "银行账号", "ID列(请勿动)"};

    //报表下载需要的表头
    private final static String[] qudaoProvinceTitle2018 = new String[]{
            "渠道", "省份", "m1", "m2",
            "m3", "m4", "m5", "m6",
            "m7", "m8", "m9", "m10",
            "m11", "m12", "2018年汇总"};

    private final static String[] qudaoSpaceTitle2018 = new String[]{
            "渠道", "片区","经理", "m1", "m2",
            "m3", "m4", "m5", "m6",
            "m7", "m8", "m9", "m10",
            "m11", "m12", "2018年汇总"};
    private final static String[] productProvinceTitle2018 = new String[]{
            "品种", "省份", "m1", "m2",
            "m3", "m4", "m5", "m6",
            "m7", "m8", "m9", "m10",
            "m11", "m12", "2018年汇总"};
    private final static String[] productSpaceTitle2018 = new String[]{
            "品种", "片区","经理", "m1", "m2",
            "m3", "m4", "m5", "m6",
            "m7", "m8", "m9", "m10",
            "m11", "m12", "2018年汇总"};

    private final static String[] qudaoProvinceTitle2017 = new String[]{
            "渠道", "省份", "m1", "m2",
            "m3", "m4", "m5", "m6",
            "m7", "m8", "m9", "m10",
            "m11", "m12", "2017年汇总"};

    private final static String[] qudaoSpaceTitle2017 = new String[]{
            "渠道", "片区","经理", "m1", "m2",
            "m3", "m4", "m5", "m6",
            "m7", "m8", "m9", "m10",
            "m11", "m12", "2017年汇总"};
    private final static String[] productProvinceTitle2017 = new String[]{
            "品种", "省份", "m1", "m2",
            "m3", "m4", "m5", "m6",
            "m7", "m8", "m9", "m10",
            "m11", "m12", "2017年汇总"};
    private final static String[] productSpaceTitle2017 = new String[]{
            "品种", "片区","经理", "m1", "m2",
            "m3", "m4", "m5", "m6",
            "m7", "m8", "m9", "m10",
            "m11", "m12", "2017年汇总"};
    private final static String[] MonthPVG1000Title2018 = new String[]{
            "分组", "终端/区县","2018年汇总", "有效月", "月均量"};
    private final static String[] MonthPVG1000Title2017 = new String[]{
            "分组", "终端/区县","2017年汇总", "有效月", "月均量"};
    //好伙伴
    private final static String[] MonthPVG1000Title2018GF = new String[]{
            "分组", "代表","2018年汇总", "有效月", "月均量"};
    //新开发终端、丢失终端情况
    private final static String[] newTerminalAndLosts = new String[]{
           "经理","大区", "片区", "省","地市","区县","渠道","分组","终端","品种","包装", "折量"};

    /**
     * 一旦容量发生变化，就要带来额外的内存开销，和时间上的开销。
     * 所以，在已经知道容量大小的情况下，推荐使用下面方式进行声明：
     * List arrayList = new ArrayList(CAPACITY_SIZE);
     * 即指定默认容量大小的方式。
     */
    private final int CAPACITY_LIST_SIZE = 128888;
    /**
     * ExcelUtils.dataToExcel调用后，就已经把数据填充到Excel并保存到了指定的路径了，但是该路径是服务器下的路径，
     * 要实现下载到客户端，则需要跳转页面额外处理，这里通过请求文件下载的servlet来实现请求。
     * 上传文件，下载文件，道理都是一样的，都是把目标文件读取到内存，然后通过输出管道写入到指定的路径。
     */

    //下载经理自己的协议
    @RequestMapping(value = "/download_policy_self.do")
    public JsonResult download_policy_self(HttpServletResponse response,HttpServletRequest request) throws Exception{
        JSONObject json = new JSONObject();
        //准备数据
        HttpSession session = request.getSession();
        User user = (User)session.getAttribute("user");
        String mgr = user.getUser_name();
        Map<String,Object> params = new HashMap<String, Object>(16);
        List<MgrsProvinces> mgrsProvinces = plansService.selectMgrsProvinces();
        List<String> provinces = new ArrayList<String>(32);
        for(MgrsProvinces s:mgrsProvinces){
            if(s.getMgr().equals(mgr)){
                if(!provinces.contains(s.getProvince())){
                    provinces.add(s.getProvince());
                }
            }
        }
        params.put("provinces",provinces);
        List<KdbNssLogClientPolicyItem> plans = plansService.download_policy_self(params);
        //把数据写入到Excel并返回文件路径和文件
        String filePath = ExcelUtils.exportCVS(plans, policysTitle);
        json.put("sucessful", 1);//关闭进度条
        json.put("filePath", "/servlet/FileDownServlet?url=" + filePath);//文件下载，请求Servlet
        ResonseUtils.writeResponseByJson(response, json);
        return null;
    }
    @RequestMapping(value = "/download_policy.do")
    public JsonResult download_policy(HttpServletResponse response,HttpServletRequest request) throws Exception{
    	JSONObject json = new JSONObject();
    	//准备数据
    	Map<String,Object> params = new HashMap<String, Object>(16);
    	
    	List<KdbNssLogClientPolicyItem> plans = plansService.download_policy(params);
    	//把数据写入到Excel并返回文件路径和文件
    	String filePath = ExcelUtils.exportCVS(plans, policysTitle);
    	json.put("sucessful", 1);//关闭进度条
    	json.put("filePath", "/servlet/FileDownServlet?url=" + filePath);//文件下载，请求Servlet
    	ResonseUtils.writeResponseByJson(response, json);
    	return null;
    }
    //下载所有流向
    @RequestMapping(value = "/download_all.do")
    public JsonResult download_all(HttpServletResponse response) {
        JSONObject json = new JSONObject();
        //准备数据
        List<ReportPlans> plans = plansService.download_all();
        //把数据写入到Excel并返回文件路径和文件
        String filePath = ExcelUtils.exportCVS(plans, plansTitle);
        json.put("sucessful", 1);//关闭进度条
        json.put("filePath", "/servlet/FileDownServlet?url=" + filePath);//文件下载，请求Servlet
        ResonseUtils.writeResponseByJson(response, json);
        return null; 
    }

    //下载2017-2018所有的流向
    @RequestMapping(value = "/download_all2017_2018Plans.do")
    public JsonResult download_all2017_2018Plans(HttpServletResponse response) {
        JSONObject json = new JSONObject();
        //准备数据  
        List<ReportPlans> plans = plansService.download_all2017_2018Plans();
        //把数据写入到Excel并返回文件路径和文件
        String filePath = ExcelUtils.exportCVS(plans, plansTitle);
        json.put("sucessful", 1);//关闭进度条
        json.put("filePath", "/servlet/FileDownServlet?url=" + filePath);//文件下载，请求Servlet
        ResonseUtils.writeResponseByJson(response, json);
        return null;
    }
    //下载2016-2018所有的纯销流向
    @RequestMapping(value = "/download_all_cx_2016_2018Plans.do")
    public JsonResult download_all_cx_2016_2018Plans(HttpServletResponse response) {
        JSONObject json = new JSONObject();
        //准备数据
        List<ReportPlans> plans = plansService.download_all_cx_2016_2018Plans();
        //把数据写入到Excel并返回文件路径和文件
        String filePath = ExcelUtils.exportCVS(plans, plansTitle);
        json.put("sucessful", 1);//关闭进度条
        json.put("filePath", "/servlet/FileDownServlet?url=" + filePath);//文件下载，请求Servlet
        ResonseUtils.writeResponseByJson(response, json);
        return null;
    }
    //下载所有的销售流向 2016-2018
    @RequestMapping(value = "/download_allXsPlans.do")
    public JsonResult download_allXsPlans(HttpServletResponse response) {
        JSONObject json = new JSONObject();
        new StringBuffer("");
        //准备数据
        List<ReportPlans> plans = plansService.download_allXsPlans();
        //把数据写入到Excel并返回文件路径和文件
        String filePath = ExcelUtils.exportCVS(plans, plansTitle);
        json.put("sucessful", 1);//关闭进度条
        json.put("filePath", "/servlet/FileDownServlet?url=" + filePath);//文件下载，请求Servlet
        ResonseUtils.writeResponseByJson(response, json);
        return null;
    }

    //下载2017年所有的流向
    @RequestMapping(value = "/download_all2017Plans.do")
    public JsonResult download_all2017Plans(HttpServletResponse response) {
        JSONObject json = new JSONObject();
        //准备数据
        List<ReportPlans> plans = plansService.download_all2017Plans();
        //把数据写入到Excel并返回文件路径和文件
        String filePath = ExcelUtils.exportCVS(plans, plansTitle);
        json.put("sucessful", 1);//关闭进度条
        json.put("filePath", "/servlet/FileDownServlet?url=" + filePath);//文件下载,请求Servlet
        ResonseUtils.writeResponseByJson(response, json);
        return null;
    }
    //下载2017年所有的流向 自己省份的 比查询所要多一个取交集的动作
    @RequestMapping(value = "/download_all2017Plans_self.do")
    public JsonResult download_all2017Plans_self(HttpServletResponse response,HttpServletRequest request) {
        HttpSession session = request.getSession();
        User user = (User)session.getAttribute("user");
        JSONObject json = new JSONObject();
        //准备数据,ReportPlans对象封装从存储过程查询过来的数据
        List<ReportPlans> plans = plansService.download_all2017Plans();
        List<ReportPlans> myPlans = new ArrayList<ReportPlans>();
        //从基础库中按经理分组，查询出所有的经理和省份的映射集合
        List<MgrsProvinces> strs = plansService.selectMgrsProvinces();
        if(strs != null && strs.size() >= 1){
            for(MgrsProvinces s:strs){
                ReportPlans r = new ReportPlans();
                if(s.getMgr()!=null && s.getMgr().equals(user.getUser_name())){
                    r.setProvince(s.getProvince());
                    //myPlans集合存放不重复的省份对应的流向，流向重写了
                    if(!myPlans.contains(r)){
                        myPlans.add(r);
                    }
                }
            }
        }
        plans.retainAll(myPlans);
        //把数据写入到Excel并返回文件路径和文件
        String filePath = ExcelUtils.exportCVS(plans, plansTitle);
        json.put("sucessful", 1);//关闭进度条
        json.put("filePath", "/servlet/FileDownServlet?url=" + filePath);//文件下载,请求Servlet
        ResonseUtils.writeResponseByJson(response, json);
        return null;
    }

    //下载2017年所有的纯销流向 自己省份的
    @RequestMapping(value = "/download_all2017CxPlans_self.do")
    public JsonResult download_all2017CxPlans_self(HttpServletResponse response,HttpServletRequest request) {
        HttpSession session = request.getSession();
        User user = (User)session.getAttribute("user");
        JSONObject json = new JSONObject();
        //准备数据
        List<ReportPlans> plans = plansService.download_all2017CxPlans();
        List<ReportPlans> myPlans = new ArrayList<ReportPlans>();
        List<MgrsProvinces> strs = plansService.selectMgrsProvinces();
        if(strs != null && strs.size() >= 1){
            for(MgrsProvinces s:strs){
                ReportPlans r = new ReportPlans();
                if(s.getMgr()!=null && s.getMgr().equals(user.getUser_name())){
                    r.setProvince(s.getProvince());
                    if(!myPlans.contains(r)){
                        myPlans.add(r);
                    }
                }
            }
        }
        plans.retainAll(myPlans);
        //把数据写入到Excel并返回文件路径和文件
        String filePath = ExcelUtils.exportCVS(plans, plansTitle);
        json.put("sucessful", 1);//关闭进度条
        json.put("filePath", "/servlet/FileDownServlet?url=" + filePath);//文件下载,请求Servlet
        ResonseUtils.writeResponseByJson(response, json);
        return null;
    }

    //下载2017年所有的销售流向
    @RequestMapping(value = "/download_all2017XsPlans.do")
    public JsonResult download_all2017XsPlans(HttpServletResponse response) {
        JSONObject json = new JSONObject();
        //准备数据
        List<ReportPlans> plans = plansService.download_all2017XsPlans();
        //把数据写入到Excel并返回文件路径和文件
        String filePath = ExcelUtils.exportCVS(plans, plansTitle);
        json.put("sucessful", 1);//关闭进度条
        json.put("filePath", "/servlet/FileDownServlet?url=" + filePath);//文件下载,请求Servlet
        ResonseUtils.writeResponseByJson(response, json);
        return null;
    }
    //下载2017年所有的销售流向 自己省份的
    @RequestMapping(value = "/download_all2017XsPlans_self.do")
    public JsonResult download_all2017XsPlans_self(HttpServletResponse response,HttpServletRequest request) {
        HttpSession session = request.getSession();
        User user = (User)session.getAttribute("user");
        JSONObject json = new JSONObject();
        //准备数据
        List<ReportPlans> plans = plansService.download_all2017XsPlans();
        List<ReportPlans> myPlans = new ArrayList<ReportPlans>();
        List<MgrsProvinces> strs = plansService.selectMgrsProvinces();
        if(strs != null && strs.size() >= 1){
            for(MgrsProvinces s:strs){
                ReportPlans r = new ReportPlans();
                if(s.getMgr()!=null && s.getMgr().equals(user.getUser_name())){
                    r.setProvince(s.getProvince());
                    if(!myPlans.contains(r)){
                        myPlans.add(r);
                    }
                }
            }
        }
        plans.retainAll(myPlans);
        //把数据写入到Excel并返回文件路径和文件
        String filePath = ExcelUtils.exportCVS(plans, plansTitle);
        json.put("sucessful", 1);//关闭进度条
        json.put("filePath", "/servlet/FileDownServlet?url=" + filePath);//文件下载,请求Servlet
        ResonseUtils.writeResponseByJson(response, json);
        return null;
    }

    //下载2018年所有流向
    @RequestMapping(value = "/download_all2018Plans.do")
    public JsonResult download_all2018Plans(HttpServletResponse response) {
        JSONObject json = new JSONObject();
        //准备数据
        List<ReportPlans> plans = plansService.download_all2018Plans();
        //把数据写入到Excel并返回文件路径和文件
        String filePath = ExcelUtils.exportCVS(plans, plansTitle);
        json.put("sucessful", 1);//关闭进度条
        json.put("filePath", "/servlet/FileDownServlet?url=" + filePath);//文件下载,请求Servlet
        ResonseUtils.writeResponseByJson(response, json);
        return null;
    }
    //下载2018年所有流向 自己省份的
    @RequestMapping(value = "/download_all2018Plans_self.do")
    public JsonResult download_all2018Plans_self(HttpServletResponse response,HttpServletRequest request) {
        HttpSession session = request.getSession();
        User user = (User)session.getAttribute("user");
        JSONObject json = new JSONObject();
        //准备数据
        List<ReportPlans> plans = plansService.download_all2018Plans();
        List<ReportPlans> myPlans = new ArrayList<ReportPlans>();
        List<MgrsProvinces> strs = plansService.selectMgrsProvinces();
        if(strs != null && strs.size() >= 1){
            for(MgrsProvinces s:strs){
                ReportPlans r = new ReportPlans();
                if(s.getMgr()!=null && s.getMgr().equals(user.getUser_name())){
                    r.setProvince(s.getProvince());
                    if(!myPlans.contains(r)){
                        myPlans.add(r);
                    }
                }
            }
        }
        plans.retainAll(myPlans);
        //把数据写入到Excel并返回文件路径和文件
        String filePath = ExcelUtils.exportCVS(plans, plansTitle);
        json.put("sucessful", 1);//关闭进度条
        json.put("filePath", "/servlet/FileDownServlet?url=" + filePath);//文件下载,请求Servlet
        ResonseUtils.writeResponseByJson(response, json);
        return null;
    }

    //全国每年纯销----------------------start-------------------------
    //下载2019年全国纯销流向
    @RequestMapping(value = "/download_all2019CxPlans.do")
    public JsonResult download_all2019CxPlans(HttpServletResponse response) {
        JSONObject json = new JSONObject();
        //准备数据
        List<ReportPlans> plans = new ArrayList<ReportPlans>(CAPACITY_LIST_SIZE);
        plans.addAll(plansService.download_all2019CxPlans());
        //把数据写入到Excel并返回文件路径和文件
        String filePath = ExcelUtils.exportCVS(plans, plansTitle);
        json.put("sucessful", 1);//关闭进度条
        json.put("filePath", "/servlet/FileDownServlet?url=" + filePath);//文件下载,请求Servlet
        ResonseUtils.writeResponseByJson(response, json);
        return null;
    }
    //下载2018年全国纯销流向
    @RequestMapping(value = "/download_all2018CxPlans.do")
    public JsonResult download_all2018CxPlans(HttpServletResponse response) {
    	JSONObject json = new JSONObject();
    	//准备数据
    	List<ReportPlans> plans = new ArrayList<ReportPlans>(CAPACITY_LIST_SIZE);
    	plans.addAll(plansService.download_all2018CxPlans());
    	//把数据写入到Excel并返回文件路径和文件
    	String filePath = ExcelUtils.exportCVS(plans, plansTitle);
    	json.put("sucessful", 1);//关闭进度条
    	json.put("filePath", "/servlet/FileDownServlet?url=" + filePath);//文件下载,请求Servlet
    	ResonseUtils.writeResponseByJson(response, json);
    	return null;
    }
    //下载2017年全国纯销流向
    @RequestMapping(value = "/download_all2017CxPlans.do")
    public JsonResult download_all2017CxPlans(HttpServletResponse response) {
        JSONObject json = new JSONObject();
        //准备数据
        List<ReportPlans> plans = new ArrayList<ReportPlans>(CAPACITY_LIST_SIZE);
        plans.addAll(plansService.download_all2017CxPlans());
        //把数据写入到Excel并返回文件路径和文件
        String filePath = ExcelUtils.exportCVS(plans, plansTitle);
        json.put("sucessful", 1);//关闭进度条
        json.put("filePath", "/servlet/FileDownServlet?url=" + filePath);//文件下载,请求Servlet
        ResonseUtils.writeResponseByJson(response, json);
        return null;
    }
    //下载2016年全国纯销流向
    @RequestMapping(value = "/download_all2016CxPlans.do")
    public JsonResult download_all2016CxPlans(HttpServletResponse response) {
        JSONObject json = new JSONObject();
        //准备数据
        List<ReportPlans> plans = new ArrayList<ReportPlans>(CAPACITY_LIST_SIZE);
        plans.addAll(plansService.download_all2016CxPlans());
        //把数据写入到Excel并返回文件路径和文件
        String filePath = ExcelUtils.exportCVS(plans, plansTitle);
        json.put("sucessful", 1);//关闭进度条
        json.put("filePath", "/servlet/FileDownServlet?url=" + filePath);//文件下载,请求Servlet
        ResonseUtils.writeResponseByJson(response, json);
        return null;
    }
    //下载2015年全国纯销流向
    @RequestMapping(value = "/download_all2015CxPlans.do")
    public JsonResult download_all2015CxPlans(HttpServletResponse response) {
        JSONObject json = new JSONObject();
        //准备数据
        List<ReportPlans> plans = new ArrayList<ReportPlans>(CAPACITY_LIST_SIZE);
        plans.addAll(plansService.download_all2015CxPlans());
        //把数据写入到Excel并返回文件路径和文件
        String filePath = ExcelUtils.exportCVS(plans, plansTitle);
        json.put("sucessful", 1);//关闭进度条
        json.put("filePath", "/servlet/FileDownServlet?url=" + filePath);//文件下载,请求Servlet
        ResonseUtils.writeResponseByJson(response, json);
        return null;
    }
    //下载2014年全国纯销流向
    @RequestMapping(value = "/download_all2014CxPlans.do")
    public JsonResult download_all2014CxPlans(HttpServletResponse response) {
        JSONObject json = new JSONObject();
        //准备数据
        List<ReportPlans> plans = new ArrayList<ReportPlans>(CAPACITY_LIST_SIZE);
        plans.addAll(plansService.download_all2014CxPlans());
        //把数据写入到Excel并返回文件路径和文件
        String filePath = ExcelUtils.exportCVS(plans, plansTitle);
        json.put("sucessful", 1);//关闭进度条
        json.put("filePath", "/servlet/FileDownServlet?url=" + filePath);//文件下载,请求Servlet
        ResonseUtils.writeResponseByJson(response, json);
        return null;
    }
    //全国每年纯销----------------------end-------------------------

    //全国连续2年纯销----------------------start-------------------------
    //下载2014-2015年全国纯销流向
    @RequestMapping(value = "/download_all2014_2015CxPlans.do")
    public JsonResult download_all2014_2015CxPlans(HttpServletResponse response) {
        JSONObject json = new JSONObject();
        //准备数据
        List<ReportPlans> plans = new ArrayList<ReportPlans>(CAPACITY_LIST_SIZE);
        plans.addAll(plansService.download_all2014_2015CxPlans());
        //把数据写入到Excel并返回文件路径和文件
        String filePath = ExcelUtils.exportCVS(plans, plansTitle);
        json.put("sucessful", 1);//关闭进度条
        json.put("filePath", "/servlet/FileDownServlet?url=" + filePath);//文件下载,请求Servlet
        ResonseUtils.writeResponseByJson(response, json);
        return null;
    }
    //下载2015-2016年全国纯销流向
    @RequestMapping(value = "/download_all2015_2016CxPlans.do")
    public JsonResult download_all2015_2016CxPlans(HttpServletResponse response) {
        JSONObject json = new JSONObject();
        //准备数据
        List<ReportPlans> plans = new ArrayList<ReportPlans>(CAPACITY_LIST_SIZE);
        plans.addAll(plansService.download_all2015_2016CxPlans());
        //把数据写入到Excel并返回文件路径和文件
        String filePath = ExcelUtils.exportCVS(plans, plansTitle);
        json.put("sucessful", 1);//关闭进度条
        json.put("filePath", "/servlet/FileDownServlet?url=" + filePath);//文件下载,请求Servlet
        ResonseUtils.writeResponseByJson(response, json);
        return null;
    }
    //下载2016-2017年全国纯销流向
    @RequestMapping(value = "/download_all2016_2017CxPlans.do")
    public JsonResult download_all2016_2017CxPlans(HttpServletResponse response) {
        JSONObject json = new JSONObject();
        //准备数据
        List<ReportPlans> plans = new ArrayList<ReportPlans>(CAPACITY_LIST_SIZE);
        plans.addAll(plansService.download_all2016_2017CxPlans());
        //把数据写入到Excel并返回文件路径和文件
        String filePath = ExcelUtils.exportCVS(plans, plansTitle);
        json.put("sucessful", 1);//关闭进度条
        json.put("filePath", "/servlet/FileDownServlet?url=" + filePath);//文件下载,请求Servlet
        ResonseUtils.writeResponseByJson(response, json);
        return null;
    }
    //下载2017-2018年全国纯销流向
    @RequestMapping(value = "/download_all2017_2018CxPlans.do")
    public JsonResult download_all2017_2018CxPlans(HttpServletResponse response) {
        JSONObject json = new JSONObject();
        //准备数据
        List<ReportPlans> plans = new ArrayList<ReportPlans>(CAPACITY_LIST_SIZE);
        plans.addAll(plansService.download_all2017_2018CxPlans());
        //把数据写入到Excel并返回文件路径和文件
        String filePath = ExcelUtils.exportCVS(plans, plansTitle);
        json.put("sucessful", 1);//关闭进度条
        json.put("filePath", "/servlet/FileDownServlet?url=" + filePath);//文件下载,请求Servlet
        ResonseUtils.writeResponseByJson(response, json);
        return null;
    }
    //下载2018-2019年全国纯销流向
    @RequestMapping(value = "/download_all2018_2019CxPlans.do")
    public JsonResult download_all2018_2019CxPlans(HttpServletResponse response) {
    	JSONObject json = new JSONObject();
    	//准备数据
    	List<ReportPlans> plans = new ArrayList<ReportPlans>(CAPACITY_LIST_SIZE);
    	plans.addAll(plansService.download_all2018_2019CxPlans());
    	//把数据写入到Excel并返回文件路径和文件
    	String filePath = ExcelUtils.exportCVS(plans, plansTitle);
    	json.put("sucessful", 1);//关闭进度条
    	json.put("filePath", "/servlet/FileDownServlet?url=" + filePath);//文件下载,请求Servlet
    	ResonseUtils.writeResponseByJson(response, json);
    	return null;
    }
    //全国连续2年纯销----------------------end-------------------------

    //经理自己省份连续2年纯销----------------------start-------------------------
    //下载2014-2015年经理自己省份纯销流向
    @RequestMapping(value = "/download_2014_2015cxPlans_self.do")
    public JsonResult download_2014_2015cxPlans_self(HttpServletRequest request,HttpServletResponse response) {
        HttpSession session = request.getSession();
        User user = (User)session.getAttribute("user");
        JSONObject json = new JSONObject();
        //准备数据
        List<ReportPlans> plans = new ArrayList<ReportPlans>(CAPACITY_LIST_SIZE);
        plans.addAll(plansService.download_all2014_2015CxPlans());
        List<ReportPlans> myPlans = new ArrayList<ReportPlans>();
        List<MgrsProvinces> strs = plansService.selectMgrsProvinces();
        if(strs != null && strs.size() >= 1){
            for(MgrsProvinces s:strs){
                ReportPlans r = new ReportPlans();
                if(s.getMgr()!=null && s.getMgr().equals(user.getUser_name())){
                    r.setProvince(s.getProvince());
                    if(!myPlans.contains(r)){
                        myPlans.add(r);
                    }
                }
            }
        }
        plans.retainAll(myPlans);
        //把数据写入到Excel并返回文件路径和文件
        String filePath = ExcelUtils.exportCVS(plans, plansTitle);
        json.put("sucessful", 1);//关闭进度条
        json.put("filePath", "/servlet/FileDownServlet?url=" + filePath);//文件下载,请求Servlet
        ResonseUtils.writeResponseByJson(response, json);
        return null;
    }
    //下载2015-2016年经理自己省份纯销流向
    @RequestMapping(value = "/download_2015_2016cxPlans_self.do")
    public JsonResult download_2015_2016cxPlans_self(HttpServletRequest request,HttpServletResponse response) {
        HttpSession session = request.getSession();
        User user = (User)session.getAttribute("user");
        JSONObject json = new JSONObject();
        //准备数据
        List<ReportPlans> plans = new ArrayList<ReportPlans>(CAPACITY_LIST_SIZE);
        plans.addAll(plansService.download_all2015_2016CxPlans());
        List<ReportPlans> myPlans = new ArrayList<ReportPlans>();
        List<MgrsProvinces> strs = plansService.selectMgrsProvinces();
        if(strs != null && strs.size() >= 1){
            for(MgrsProvinces s:strs){
                ReportPlans r = new ReportPlans();
                if(s.getMgr()!=null && s.getMgr().equals(user.getUser_name())){
                    r.setProvince(s.getProvince());
                    if(!myPlans.contains(r)){
                        myPlans.add(r);
                    }
                }
            }
        }
        plans.retainAll(myPlans);
        //把数据写入到Excel并返回文件路径和文件
        String filePath = ExcelUtils.exportCVS(plans, plansTitle);
        json.put("sucessful", 1);//关闭进度条
        json.put("filePath", "/servlet/FileDownServlet?url=" + filePath);//文件下载,请求Servlet
        ResonseUtils.writeResponseByJson(response, json);
        return null;
    }
    //下载2016-2017年经理自己省份纯销流向
    @RequestMapping(value = "/download_2016_2017cxPlans_self.do")
    public JsonResult download_2016_2017cxPlans_self(HttpServletRequest request,HttpServletResponse response) {
        HttpSession session = request.getSession();
        User user = (User)session.getAttribute("user");
        JSONObject json = new JSONObject();
        //准备数据
        List<ReportPlans> plans = new ArrayList<ReportPlans>(CAPACITY_LIST_SIZE);
        plans.addAll(plansService.download_all2016_2017CxPlans());
        List<ReportPlans> myPlans = new ArrayList<ReportPlans>();
        List<MgrsProvinces> strs = plansService.selectMgrsProvinces();
        if(strs != null && strs.size() >= 1){
            for(MgrsProvinces s:strs){
                ReportPlans r = new ReportPlans();
                if(s.getMgr()!=null && s.getMgr().equals(user.getUser_name())){
                    r.setProvince(s.getProvince());
                    if(!myPlans.contains(r)){
                        myPlans.add(r);
                    }
                }
            }
        }
        plans.retainAll(myPlans);
        //把数据写入到Excel并返回文件路径和文件
        String filePath = ExcelUtils.exportCVS(plans, plansTitle);
        json.put("sucessful", 1);//关闭进度条
        json.put("filePath", "/servlet/FileDownServlet?url=" + filePath);//文件下载,请求Servlet
        ResonseUtils.writeResponseByJson(response, json);
        return null;
    }
    //下载2017-2018年经理自己省份纯销流向
    @RequestMapping(value = "/download_2017_2018cxPlans_self.do")
    public JsonResult download_2017_2018cxPlans_self(HttpServletRequest request,HttpServletResponse response) {
        HttpSession session = request.getSession();
        User user = (User)session.getAttribute("user");
        JSONObject json = new JSONObject();
        //准备数据
        List<ReportPlans> plans = new ArrayList<ReportPlans>(CAPACITY_LIST_SIZE);
        plans.addAll(plansService.download_all2017_2018CxPlans());
        List<ReportPlans> myPlans = new ArrayList<ReportPlans>();
        List<MgrsProvinces> strs = plansService.selectMgrsProvinces();
        if(strs != null && strs.size() >= 1){
            for(MgrsProvinces s:strs){
                ReportPlans r = new ReportPlans();
                if(s.getMgr()!=null && s.getMgr().equals(user.getUser_name())){
                    r.setProvince(s.getProvince());
                    if(!myPlans.contains(r)){
                        myPlans.add(r);
                    }
                }
            }
        }
        plans.retainAll(myPlans);
        //把数据写入到Excel并返回文件路径和文件
        String filePath = ExcelUtils.exportCVS(plans, plansTitle);
        json.put("sucessful", 1);//关闭进度条
        json.put("filePath", "/servlet/FileDownServlet?url=" + filePath);//文件下载,请求Servlet
        ResonseUtils.writeResponseByJson(response, json);
        return null;
    }
    //下载2018-2019年经理自己省份纯销流向
    @RequestMapping(value = "/download_2018_2019cxPlans_self.do")
    public JsonResult download_2018_2019cxPlans_self(HttpServletRequest request,HttpServletResponse response) {
    	HttpSession session = request.getSession();
    	User user = (User)session.getAttribute("user");
    	JSONObject json = new JSONObject();
    	//准备数据
    	List<ReportPlans> plans = new ArrayList<ReportPlans>(CAPACITY_LIST_SIZE);
    	plans.addAll(plansService.download_all2018_2019CxPlans());
    	List<ReportPlans> myPlans = new ArrayList<ReportPlans>();
    	List<MgrsProvinces> strs = plansService.selectMgrsProvinces();
    	if(strs != null && strs.size() >= 1){
    		for(MgrsProvinces s:strs){
    			ReportPlans r = new ReportPlans();
    			if(s.getMgr()!=null && s.getMgr().equals(user.getUser_name())){
    				r.setProvince(s.getProvince());
    				if(!myPlans.contains(r)){
    					myPlans.add(r);
    				}
    			}
    		}
    	}
    	plans.retainAll(myPlans);
    	//把数据写入到Excel并返回文件路径和文件
    	String filePath = ExcelUtils.exportCVS(plans, plansTitle);
    	json.put("sucessful", 1);//关闭进度条
    	json.put("filePath", "/servlet/FileDownServlet?url=" + filePath);//文件下载,请求Servlet
    	ResonseUtils.writeResponseByJson(response, json);
    	return null;
    }
    //经理自己省份连续2年纯销----------------------end-------------------------

    //经理自己省份每年纯销---------------------start-------------------------
    //下载2014年经理自己省份纯销流向
    @RequestMapping(value = "/download_2014cxPlans_self.do")
    public JsonResult download_2014cxPlans_self(HttpServletRequest request,HttpServletResponse response) {
        HttpSession session = request.getSession();
        User user = (User)session.getAttribute("user");
        JSONObject json = new JSONObject();
        //准备数据
        List<ReportPlans> plans = new ArrayList<ReportPlans>(CAPACITY_LIST_SIZE);
        plans.addAll(plansService.download_all2014CxPlans());
        List<ReportPlans> myPlans = new ArrayList<ReportPlans>();
        List<MgrsProvinces> strs = plansService.selectMgrsProvinces();
        if(strs != null && strs.size() >= 1){
            for(MgrsProvinces s:strs){
                ReportPlans r = new ReportPlans();
                if(s.getMgr()!=null && s.getMgr().equals(user.getUser_name())){
                    r.setProvince(s.getProvince());
                    if(!myPlans.contains(r)){
                        myPlans.add(r);
                    }
                }
            }
        }
        plans.retainAll(myPlans);
        //把数据写入到Excel并返回文件路径和文件
        String filePath = ExcelUtils.exportCVS(plans, plansTitle);
        json.put("sucessful", 1);//关闭进度条
        json.put("filePath", "/servlet/FileDownServlet?url=" + filePath);//文件下载,请求Servlet
        ResonseUtils.writeResponseByJson(response, json);
        return null;
    }
    //下载2015年经理自己省份纯销流向
    @RequestMapping(value = "/download_2015cxPlans_self.do")
    public JsonResult download_2015cxPlans_self(HttpServletRequest request,HttpServletResponse response) {
        HttpSession session = request.getSession();
        User user = (User)session.getAttribute("user");
        JSONObject json = new JSONObject();
        //准备数据
        List<ReportPlans> plans = new ArrayList<ReportPlans>(CAPACITY_LIST_SIZE);
        plans.addAll(plansService.download_all2015CxPlans());
        List<ReportPlans> myPlans = new ArrayList<ReportPlans>();
        List<MgrsProvinces> strs = plansService.selectMgrsProvinces();
        if(strs != null && strs.size() >= 1){
            for(MgrsProvinces s:strs){
                ReportPlans r = new ReportPlans();
                if(s.getMgr()!=null && s.getMgr().equals(user.getUser_name())){
                    r.setProvince(s.getProvince());
                    if(!myPlans.contains(r)){
                        myPlans.add(r);
                    }
                }
            }
        }
        plans.retainAll(myPlans);
        //把数据写入到Excel并返回文件路径和文件
        String filePath = ExcelUtils.exportCVS(plans, plansTitle);
        json.put("sucessful", 1);//关闭进度条
        json.put("filePath", "/servlet/FileDownServlet?url=" + filePath);//文件下载,请求Servlet
        ResonseUtils.writeResponseByJson(response, json);
        return null;
    }
    //下载2016年经理自己省份纯销流向
    @RequestMapping(value = "/download_2016cxPlans_self.do")
    public JsonResult download_2016cxPlans_self(HttpServletRequest request,HttpServletResponse response) {
        HttpSession session = request.getSession();
        User user = (User)session.getAttribute("user");
        JSONObject json = new JSONObject();
        //准备数据
        List<ReportPlans> plans = new ArrayList<ReportPlans>(CAPACITY_LIST_SIZE);
        plans.addAll(plansService.download_all2016CxPlans());
        List<ReportPlans> myPlans = new ArrayList<ReportPlans>();
        List<MgrsProvinces> strs = plansService.selectMgrsProvinces();
        if(strs != null && strs.size() >= 1){
            for(MgrsProvinces s:strs){
                ReportPlans r = new ReportPlans();
                if(s.getMgr()!=null && s.getMgr().equals(user.getUser_name())){
                    r.setProvince(s.getProvince());
                    if(!myPlans.contains(r)){
                        myPlans.add(r);
                    }
                }
            }
        }
        plans.retainAll(myPlans);
        //把数据写入到Excel并返回文件路径和文件
        String filePath = ExcelUtils.exportCVS(plans, plansTitle);
        json.put("sucessful", 1);//关闭进度条
        json.put("filePath", "/servlet/FileDownServlet?url=" + filePath);//文件下载,请求Servlet
        ResonseUtils.writeResponseByJson(response, json);
        return null;
    }
    //下载2017年经理自己省份纯销流向
    @RequestMapping(value = "/download_2017cxPlans_self.do")
    public JsonResult download_2017cxPlans_self(HttpServletRequest request,HttpServletResponse response) {
        HttpSession session = request.getSession();
        User user = (User)session.getAttribute("user");
        JSONObject json = new JSONObject();
        //准备数据
        List<ReportPlans> plans = new ArrayList<ReportPlans>(CAPACITY_LIST_SIZE);
        plans.addAll(plansService.download_all2017CxPlans());
        List<ReportPlans> myPlans = new ArrayList<ReportPlans>();
        List<MgrsProvinces> strs = plansService.selectMgrsProvinces();
        if(strs != null && strs.size() >= 1){
            for(MgrsProvinces s:strs){
                ReportPlans r = new ReportPlans();
                if(s.getMgr()!=null && s.getMgr().equals(user.getUser_name())){
                    r.setProvince(s.getProvince());
                    if(!myPlans.contains(r)){
                        myPlans.add(r);
                    }
                }
            }
        }
        plans.retainAll(myPlans);
        //把数据写入到Excel并返回文件路径和文件
        String filePath = ExcelUtils.exportCVS(plans, plansTitle);
        json.put("sucessful", 1);//关闭进度条
        json.put("filePath", "/servlet/FileDownServlet?url=" + filePath);//文件下载,请求Servlet
        ResonseUtils.writeResponseByJson(response, json);
        return null;
    }
    //下载2018年经理自己省份纯销流向
    @RequestMapping(value = "/download_2018cxPlans_self.do")
    public JsonResult download_2018cxPlans_self(HttpServletRequest request,HttpServletResponse response) {
        HttpSession session = request.getSession();
        User user = (User)session.getAttribute("user");
        JSONObject json = new JSONObject();
        //准备数据
        List<ReportPlans> plans = new ArrayList<ReportPlans>(CAPACITY_LIST_SIZE);
        plans.addAll(plansService.download_all2018CxPlans());
        List<ReportPlans> myPlans = new ArrayList<ReportPlans>();
        List<MgrsProvinces> strs = plansService.selectMgrsProvinces();
        if(strs != null && strs.size() >= 1){
            for(MgrsProvinces s:strs){
                ReportPlans r = new ReportPlans();
                if(s.getMgr()!=null && s.getMgr().equals(user.getUser_name())){
                    r.setProvince(s.getProvince());
                    if(!myPlans.contains(r)){
                        myPlans.add(r);
                    }
                }
            }
        }
        plans.retainAll(myPlans);
        //把数据写入到Excel并返回文件路径和文件
        String filePath = ExcelUtils.exportCVS(plans, plansTitle);
        json.put("sucessful", 1);//关闭进度条
        json.put("filePath", "/servlet/FileDownServlet?url=" + filePath);//文件下载,请求Servlet
        ResonseUtils.writeResponseByJson(response, json);
        return null;
    }
    //下载2019年经理自己省份纯销流向
    @RequestMapping(value = "/download_2019cxPlans_self.do")
    public JsonResult download_2019cxPlans_self(HttpServletRequest request,HttpServletResponse response) {
    	HttpSession session = request.getSession();
    	User user = (User)session.getAttribute("user");
    	JSONObject json = new JSONObject();
    	//准备数据
    	List<ReportPlans> plans = new ArrayList<ReportPlans>(CAPACITY_LIST_SIZE);
    	plans.addAll(plansService.download_all2019CxPlans());
    	List<ReportPlans> myPlans = new ArrayList<ReportPlans>();
    	List<MgrsProvinces> strs = plansService.selectMgrsProvinces();
    	if(strs != null && strs.size() >= 1){
    		for(MgrsProvinces s:strs){
    			ReportPlans r = new ReportPlans();
    			if(s.getMgr()!=null && s.getMgr().equals(user.getUser_name())){
    				r.setProvince(s.getProvince());
    				if(!myPlans.contains(r)){
    					myPlans.add(r);
    				}
    			}
    		}
    	}
    	plans.retainAll(myPlans);
    	//把数据写入到Excel并返回文件路径和文件
    	String filePath = ExcelUtils.exportCVS(plans, plansTitle);
    	json.put("sucessful", 1);//关闭进度条
    	json.put("filePath", "/servlet/FileDownServlet?url=" + filePath);//文件下载,请求Servlet
    	ResonseUtils.writeResponseByJson(response, json);
    	return null;
    }
    //经理自己省份每年纯销---------------------end-------------------------

    //全国所有行为流向------------------start---------------------
    //下载2014年经理自己省份所有的流向
    @RequestMapping(value = "/download_2014_allPlans.do")
    public JsonResult download_2014_allPlans(HttpServletRequest request,HttpServletResponse response) {
        JSONObject json = new JSONObject();
        //准备数据
        List<ReportPlans> plans = new ArrayList<ReportPlans>(CAPACITY_LIST_SIZE);
        plans.addAll(plansService.download_all2014Plans());
        //把数据写入到Excel并返回文件路径和文件
        String filePath = ExcelUtils.exportCVS(plans, plansTitle);
        json.put("sucessful", 1);//关闭进度条
        json.put("filePath", "/servlet/FileDownServlet?url=" + filePath);//文件下载,请求Servlet
        ResonseUtils.writeResponseByJson(response, json);
        return null;
    }
    //下载2015年经理自己省份所有的流向
    @RequestMapping(value = "/download_2015_allPlans.do")
    public JsonResult download_2015_allPlans(HttpServletRequest request,HttpServletResponse response) {
        JSONObject json = new JSONObject();
        //准备数据
        List<ReportPlans> plans = new ArrayList<ReportPlans>(CAPACITY_LIST_SIZE);
        plans.addAll(plansService.download_all2015Plans());
        //把数据写入到Excel并返回文件路径和文件
        String filePath = ExcelUtils.exportCVS(plans, plansTitle);
        json.put("sucessful", 1);//关闭进度条
        json.put("filePath", "/servlet/FileDownServlet?url=" + filePath);//文件下载,请求Servlet
        ResonseUtils.writeResponseByJson(response, json);
        return null;
    }
    //下载2016年经理自己省份所有的流向
    @RequestMapping(value = "/download_2016_allPlans.do")
    public JsonResult download_2016_allPlans(HttpServletRequest request,HttpServletResponse response) {
        JSONObject json = new JSONObject();
        //准备数据
        List<ReportPlans> plans = new ArrayList<ReportPlans>(CAPACITY_LIST_SIZE);
        plans.addAll(plansService.download_all2016Plans());
        //把数据写入到Excel并返回文件路径和文件
        String filePath = ExcelUtils.exportCVS(plans, plansTitle);
        json.put("sucessful", 1);//关闭进度条
        json.put("filePath", "/servlet/FileDownServlet?url=" + filePath);//文件下载,请求Servlet
        ResonseUtils.writeResponseByJson(response, json);
        return null;
    }
    //下载2017年经理自己省份所有的流向
    @RequestMapping(value = "/download_2017_allPlans.do")
    public JsonResult download_2017_allPlans(HttpServletRequest request,HttpServletResponse response) {
        JSONObject json = new JSONObject();
        //准备数据
        List<ReportPlans> plans = new ArrayList<ReportPlans>(CAPACITY_LIST_SIZE);
        plans.addAll(plansService.download_all2017Plans());
        //把数据写入到Excel并返回文件路径和文件
        String filePath = ExcelUtils.exportCVS(plans, plansTitle);
        json.put("sucessful", 1);//关闭进度条
        json.put("filePath", "/servlet/FileDownServlet?url=" + filePath);//文件下载,请求Servlet
        ResonseUtils.writeResponseByJson(response, json);
        return null;
    }
    //下载2018年省份所有的流向
    @RequestMapping(value = "/download_2018_allPlans.do")
    public JsonResult download_2018_allPlans(HttpServletRequest request,HttpServletResponse response) {
        JSONObject json = new JSONObject();
        //准备数据
        List<ReportPlans> plans = new ArrayList<ReportPlans>(CAPACITY_LIST_SIZE);
        plans.addAll(plansService.download_all2018Plans());
        //把数据写入到Excel并返回文件路径和文件
        String filePath = ExcelUtils.exportCVS(plans, plansTitle);
        json.put("sucessful", 1);//关闭进度条
        json.put("filePath", "/servlet/FileDownServlet?url=" + filePath);//文件下载,请求Servlet
        ResonseUtils.writeResponseByJson(response, json);
        return null;
    }
    //下载2019年省份所有的流向
    @RequestMapping(value = "/download_2019_allPlans.do")
    public JsonResult download_2019_allPlans(HttpServletRequest request,HttpServletResponse response) {
    	JSONObject json = new JSONObject();
    	//准备数据
    	List<ReportPlans> plans = new ArrayList<ReportPlans>(CAPACITY_LIST_SIZE);
    	plans.addAll(plansService.download_all2019Plans());
    	//把数据写入到Excel并返回文件路径和文件
    	String filePath = ExcelUtils.exportCVS(plans, plansTitle);
    	json.put("sucessful", 1);//关闭进度条
    	json.put("filePath", "/servlet/FileDownServlet?url=" + filePath);//文件下载,请求Servlet
    	ResonseUtils.writeResponseByJson(response, json);
    	return null;
    }
    //下载2017-2018年省份所有的流向
    @RequestMapping(value = "/download_2017_2018_allPlans.do")
    public JsonResult download_2017_2018_allPlans(HttpServletRequest request,HttpServletResponse response) {
        System.out.println("download_2017_2018_allPlans.do........");
    	JSONObject json = new JSONObject();
        //准备数据
        List<ReportPlans> plans = new ArrayList<ReportPlans>();
        plans.addAll(plansService.download_2017_2018_allPlans());
        System.out.println("plans.size:"+plans.size());
        //System.out.println("初始化："+(end-start)/1000); 
        //把数据写入到Excel并返回文件路径和文件
        String filePath = ExcelUtils.exportCVS(plans, plansTitle);
        json.put("sucessful", 1);//关闭进度条
        json.put("filePath", "/servlet/FileDownServlet?url=" + filePath);//文件下载,请求Servlet
        ResonseUtils.writeResponseByJson(response, json);
        return null;
    }
    //下载2018-2019年省份所有的流向
    @RequestMapping(value = "/download_2018_2019_allPlans.do")
    public JsonResult download_2018_2019_allPlans(HttpServletRequest request,HttpServletResponse response) {
    	JSONObject json = new JSONObject();
    	//准备数据
    	List<ReportPlans> plans = new ArrayList<ReportPlans>();
    	plans.addAll(plansService.download_2018_2019_allPlans());
    	//System.out.println("初始化："+(end-start)/1000); 
    	//把数据写入到Excel并返回文件路径和文件
    	String filePath = ExcelUtils.exportCVS(plans, plansTitle);
    	json.put("sucessful", 1);//关闭进度条
    	json.put("filePath", "/servlet/FileDownServlet?url=" + filePath);//文件下载,请求Servlet
    	ResonseUtils.writeResponseByJson(response, json);
    	return null;
    }
    //下载2018-2019年省份所有的流向，简版本
    @RequestMapping(value = "/download_2018_2019_allPlans_J.do")
    public JsonResult download_2018_2019_allPlans_J(HttpServletRequest request,HttpServletResponse response) {
    	JSONObject json = new JSONObject();
    	//准备数据
    	List<ReportPlansJ> plans = new ArrayList<ReportPlansJ>();
    	plans.addAll(plansService.download_2018_2019_allPlans_J());
    	//把数据写入到Excel并返回文件路径和文件
    	String filePath = ExcelUtils.exportCVS(plans, plansTitle_J);
    	json.put("sucessful", 1);//关闭进度条
    	json.put("filePath", "/servlet/FileDownServlet?url=" + filePath);//文件下载,请求Servlet
    	ResonseUtils.writeResponseByJson(response, json);
    	return null;
    }
    //下载2018-2019年省份所有的流向，中版本
    @RequestMapping(value = "/download_2018_2019_allPlans_Z.do")
    public JsonResult download_2018_2019_allPlans_Z(HttpServletRequest request,HttpServletResponse response) {
    	JSONObject json = new JSONObject();
    	//准备数据
    	List<ReportPlansZ> plans = new ArrayList<ReportPlansZ>();
    	plans.addAll(plansService.download_2018_2019_allPlans_Z());
    	//把数据写入到Excel并返回文件路径和文件
    	String filePath = ExcelUtils.exportCVS(plans, plansTitle_Z);
    	json.put("sucessful", 1);//关闭进度条
    	json.put("filePath", "/servlet/FileDownServlet?url=" + filePath);//文件下载,请求Servlet
    	ResonseUtils.writeResponseByJson(response, json);
    	return null;
    }
    //下载2018-2019年省份所有的流向,全版本
    @RequestMapping(value = "/download_2018_2019_allPlans_Q.do")
    public JsonResult download_2018_2019_allPlans_Q(HttpServletRequest request,HttpServletResponse response) {
    	JSONObject json = new JSONObject();
    	//准备数据
    	List<ReportPlansQ> plans = new ArrayList<ReportPlansQ>();
    	plans.addAll(plansService.download_2018_2019_allPlans_Q());
    	//把数据写入到Excel并返回文件路径和文件
    	String filePath = ExcelUtils.exportCVS(plans, plansTitle_Q);
    	json.put("sucessful", 1);//关闭进度条
    	json.put("filePath", "/servlet/FileDownServlet?url=" + filePath);//文件下载,请求Servlet
    	ResonseUtils.writeResponseByJson(response, json);
    	return null;
    }
    //全国所有行为流向------------------end---------------------

    //经理自己省份每年所有的流向-------------------start-------------------------
    //下载2014年经理自己省份所有的流向
    @RequestMapping(value = "/download_2014_allPlans_self.do")
    public JsonResult download_2014_allPlans_self(HttpServletRequest request,HttpServletResponse response) {
        HttpSession session = request.getSession();
        User user = (User)session.getAttribute("user");
        JSONObject json = new JSONObject();
        //准备数据
        List<ReportPlans> plans = new ArrayList<ReportPlans>(CAPACITY_LIST_SIZE);
        plans.addAll(plansService.download_all2014Plans());
        List<ReportPlans> myPlans = new ArrayList<ReportPlans>();
        List<MgrsProvinces> strs = plansService.selectMgrsProvinces();
        if(strs != null && strs.size() >= 1){
            for(MgrsProvinces s:strs){
                ReportPlans r = new ReportPlans();
                if(s.getMgr()!=null && s.getMgr().equals(user.getUser_name())){
                    r.setProvince(s.getProvince());
                    if(!myPlans.contains(r)){
                        myPlans.add(r);
                    }
                }
            }
        }
        plans.retainAll(myPlans);
        //把数据写入到Excel并返回文件路径和文件
        String filePath = ExcelUtils.exportCVS(plans, plansTitle);
        json.put("sucessful", 1);//关闭进度条
        json.put("filePath", "/servlet/FileDownServlet?url=" + filePath);//文件下载,请求Servlet
        ResonseUtils.writeResponseByJson(response, json);
        return null;
    }
    //下载2015年经理自己省份所有的流向
    @RequestMapping(value = "/download_2015_allPlans_self.do")
    public JsonResult download_2015_allPlans_self(HttpServletRequest request,HttpServletResponse response) {
        HttpSession session = request.getSession();
        User user = (User)session.getAttribute("user");
        JSONObject json = new JSONObject();
        //准备数据
        List<ReportPlans> plans = new ArrayList<ReportPlans>(CAPACITY_LIST_SIZE);
        plans.addAll(plansService.download_all2015Plans());
        List<ReportPlans> myPlans = new ArrayList<ReportPlans>();
        List<MgrsProvinces> strs = plansService.selectMgrsProvinces();
        if(strs != null && strs.size() >= 1){
            for(MgrsProvinces s:strs){
                ReportPlans r = new ReportPlans();
                if(s.getMgr()!=null && s.getMgr().equals(user.getUser_name())){
                    r.setProvince(s.getProvince());
                    if(!myPlans.contains(r)){
                        myPlans.add(r);
                    }
                }
            }
        }
        plans.retainAll(myPlans);
        //把数据写入到Excel并返回文件路径和文件
        String filePath = ExcelUtils.exportCVS(plans, plansTitle);
        json.put("sucessful", 1);//关闭进度条
        json.put("filePath", "/servlet/FileDownServlet?url=" + filePath);//文件下载,请求Servlet
        ResonseUtils.writeResponseByJson(response, json);
        return null;
    }
    //下载2016年经理自己省份所有的流向
    @RequestMapping(value = "/download_2016_allPlans_self.do")
    public JsonResult download_2016_allPlans_self(HttpServletRequest request,HttpServletResponse response) {
        HttpSession session = request.getSession();
        User user = (User)session.getAttribute("user");
        JSONObject json = new JSONObject();
        //准备数据
        List<ReportPlans> plans = new ArrayList<ReportPlans>(CAPACITY_LIST_SIZE);
        plans.addAll(plansService.download_all2016Plans());
        List<ReportPlans> myPlans = new ArrayList<ReportPlans>();
        List<MgrsProvinces> strs = plansService.selectMgrsProvinces();
        if(strs != null && strs.size() >= 1){
            for(MgrsProvinces s:strs){
                ReportPlans r = new ReportPlans();
                if(s.getMgr()!=null && s.getMgr().equals(user.getUser_name())){
                    r.setProvince(s.getProvince());
                    if(!myPlans.contains(r)){
                        myPlans.add(r);
                    }
                }
            }
        }
        plans.retainAll(myPlans);
        //把数据写入到Excel并返回文件路径和文件
        String filePath = ExcelUtils.exportCVS(plans, plansTitle);
        json.put("sucessful", 1);//关闭进度条
        json.put("filePath", "/servlet/FileDownServlet?url=" + filePath);//文件下载,请求Servlet
        ResonseUtils.writeResponseByJson(response, json);
        return null;
    }
    //下载2017年经理自己省份纯销流向
    @RequestMapping(value = "/download_2017_allPlans_self.do")
    public JsonResult download_2017_allPlans_self(HttpServletRequest request,HttpServletResponse response) {
        HttpSession session = request.getSession();
        User user = (User)session.getAttribute("user");
        JSONObject json = new JSONObject();
        //准备数据
        List<ReportPlans> plans = new ArrayList<ReportPlans>(CAPACITY_LIST_SIZE);
        plans.addAll(plansService.download_all2017Plans());
        List<ReportPlans> myPlans = new ArrayList<ReportPlans>();
        List<MgrsProvinces> strs = plansService.selectMgrsProvinces();
        if(strs != null && strs.size() >= 1){
            for(MgrsProvinces s:strs){
                ReportPlans r = new ReportPlans();
                if(s.getMgr()!=null && s.getMgr().equals(user.getUser_name())){
                    r.setProvince(s.getProvince());
                    if(!myPlans.contains(r)){
                        myPlans.add(r);
                    }
                }
            }
        }
        plans.retainAll(myPlans);
        //把数据写入到Excel并返回文件路径和文件
        String filePath = ExcelUtils.exportCVS(plans, plansTitle);
        json.put("sucessful", 1);//关闭进度条
        json.put("filePath", "/servlet/FileDownServlet?url=" + filePath);//文件下载,请求Servlet
        ResonseUtils.writeResponseByJson(response, json);
        return null;
    }
    //下载2018年经理自己省份纯销流向
    @RequestMapping(value = "/download_2018_allPlans_self.do")
    public JsonResult download_2018_allPlans_self(HttpServletRequest request,HttpServletResponse response) {
        HttpSession session = request.getSession();
        User user = (User)session.getAttribute("user");
        JSONObject json = new JSONObject();
        //准备数据
        List<ReportPlans> plans = new ArrayList<ReportPlans>(CAPACITY_LIST_SIZE);
        plans.addAll(plansService.download_all2018Plans());
        List<ReportPlans> myPlans = new ArrayList<ReportPlans>();
        List<MgrsProvinces> strs = plansService.selectMgrsProvinces();
        if(strs != null && strs.size() >= 1){
            for(MgrsProvinces s:strs){
                ReportPlans r = new ReportPlans();
                if(s.getMgr()!=null && s.getMgr().equals(user.getUser_name())){
                    r.setProvince(s.getProvince());
                    if(!myPlans.contains(r)){
                        myPlans.add(r);
                    }
                }
            }
        }
        plans.retainAll(myPlans);
        //把数据写入到Excel并返回文件路径和文件
        String filePath = ExcelUtils.exportCVS(plans, plansTitle);
        json.put("sucessful", 1);//关闭进度条
        json.put("filePath", "/servlet/FileDownServlet?url=" + filePath);//文件下载,请求Servlet
        ResonseUtils.writeResponseByJson(response, json);
        return null;
    }
    //下载2019年经理自己省份纯销流向
    @RequestMapping(value = "/download_2019_allPlans_self.do")
    public JsonResult download_2019_allPlans_self(HttpServletRequest request,HttpServletResponse response) {
    	HttpSession session = request.getSession();
    	User user = (User)session.getAttribute("user");
    	JSONObject json = new JSONObject();
    	//准备数据
    	List<ReportPlans> plans = new ArrayList<ReportPlans>(CAPACITY_LIST_SIZE);
    	plans.addAll(plansService.download_all2019Plans());
    	List<ReportPlans> myPlans = new ArrayList<ReportPlans>();
    	List<MgrsProvinces> strs = plansService.selectMgrsProvinces();
    	if(strs != null && strs.size() >= 1){
    		for(MgrsProvinces s:strs){
    			ReportPlans r = new ReportPlans();
    			if(s.getMgr()!=null && s.getMgr().equals(user.getUser_name())){
    				r.setProvince(s.getProvince());
    				if(!myPlans.contains(r)){
    					myPlans.add(r);
    				}
    			}
    		}
    	}
    	plans.retainAll(myPlans);
    	//把数据写入到Excel并返回文件路径和文件
    	String filePath = ExcelUtils.exportCVS(plans, plansTitle);
    	json.put("sucessful", 1);//关闭进度条
    	json.put("filePath", "/servlet/FileDownServlet?url=" + filePath);//文件下载,请求Servlet
    	ResonseUtils.writeResponseByJson(response, json);
    	return null;
    }
    //下载2017-2018年经理自己省份纯销流向
    @RequestMapping(value = "/download_2017_2018_allPlans_self.do")
    public JsonResult download_2017_2018_allPlans_self(HttpServletRequest request,HttpServletResponse response) {
        HttpSession session = request.getSession();
        User user = (User)session.getAttribute("user");
        JSONObject json = new JSONObject();
        //准备数据
        List<ReportPlans> plans = new ArrayList<ReportPlans>(CAPACITY_LIST_SIZE);
        plans.addAll(plansService.download_2017_2018_allPlans());
        List<ReportPlans> myPlans = new ArrayList<ReportPlans>();
        List<MgrsProvinces> strs = plansService.selectMgrsProvinces();
        if(strs != null && strs.size() >= 1){
            for(MgrsProvinces s:strs){
                ReportPlans r = new ReportPlans();
                if(s.getMgr()!=null && s.getMgr().equals(user.getUser_name())){
                    r.setProvince(s.getProvince());
                    if(!myPlans.contains(r)){
                        myPlans.add(r);
                    }
                }
            }
        }
        plans.retainAll(myPlans);
        //把数据写入到Excel并返回文件路径和文件
        String filePath = ExcelUtils.exportCVS(plans, plansTitle);
        json.put("sucessful", 1);//关闭进度条
        json.put("filePath", "/servlet/FileDownServlet?url=" + filePath);//文件下载,请求Servlet
        ResonseUtils.writeResponseByJson(response, json);
        return null;
    }
    //下载2018-2019年经理自己省份纯销流向
    @RequestMapping(value = "/download_2018_2019_allPlans_self.do")
    public JsonResult download_2018_2019_allPlans_self(HttpServletRequest request,HttpServletResponse response) {
    	HttpSession session = request.getSession();
    	User user = (User)session.getAttribute("user");
    	JSONObject json = new JSONObject();
    	//准备数据
    	List<ReportPlans> plans = new ArrayList<ReportPlans>(CAPACITY_LIST_SIZE);
    	plans.addAll(plansService.download_2018_2019_allPlans());
    	List<ReportPlans> myPlans = new ArrayList<ReportPlans>();
    	List<MgrsProvinces> strs = plansService.selectMgrsProvinces();
    	if(strs != null && strs.size() >= 1){
    		for(MgrsProvinces s:strs){
    			ReportPlans r = new ReportPlans();
    			if(s.getMgr()!=null && s.getMgr().equals(user.getUser_name())){
    				r.setProvince(s.getProvince());
    				if(!myPlans.contains(r)){
    					myPlans.add(r);
    				}
    			}
    		}
    	}
    	plans.retainAll(myPlans);
    	//把数据写入到Excel并返回文件路径和文件
    	String filePath = ExcelUtils.exportCVS(plans, plansTitle);
    	json.put("sucessful", 1);//关闭进度条
    	json.put("filePath", "/servlet/FileDownServlet?url=" + filePath);//文件下载,请求Servlet
    	ResonseUtils.writeResponseByJson(response, json);
    	return null;
    }
    //经理自己省份每年纯销---------------------end-------------------------

    //经理自己省份连续2年销售---------------------start-------------------------
    //下载2014-2015年经理自己省份销售流向
    @RequestMapping(value = "/download_2014_2015xsPlans_self.do")
    public JsonResult download_2014_2015xsPlans_self(HttpServletRequest request,HttpServletResponse response) {
        HttpSession session = request.getSession();
        User user = (User)session.getAttribute("user");
        JSONObject json = new JSONObject();
        //准备数据
        List<ReportPlans> plans = new ArrayList<ReportPlans>(CAPACITY_LIST_SIZE);
        plans.addAll(plansService.download_all2014_2015XsPlans());
        List<ReportPlans> myPlans = new ArrayList<ReportPlans>();
        List<MgrsProvinces> strs = plansService.selectMgrsProvinces();
        if(strs != null && strs.size() >= 1){
            for(MgrsProvinces s:strs){
                ReportPlans r = new ReportPlans();
                if(s.getMgr()!=null && s.getMgr().equals(user.getUser_name())){
                    r.setProvince(s.getProvince());
                    if(!myPlans.contains(r)){
                        myPlans.add(r);
                    }
                }
            }
        }
        plans.retainAll(myPlans);
        //把数据写入到Excel并返回文件路径和文件
        String filePath = ExcelUtils.exportCVS(plans, plansTitle);
        json.put("sucessful", 1);//关闭进度条
        json.put("filePath", "/servlet/FileDownServlet?url=" + filePath);//文件下载,请求Servlet
        ResonseUtils.writeResponseByJson(response, json);
        return null;
    }
    //下载2015-2016年经理自己省份销售流向
    @RequestMapping(value = "/download_2015_2016xsPlans_self.do")
    public JsonResult download_2015_2016xsPlans_self(HttpServletRequest request,HttpServletResponse response) {
        HttpSession session = request.getSession();
        User user = (User)session.getAttribute("user");
        JSONObject json = new JSONObject();
        //准备数据
        List<ReportPlans> plans = new ArrayList<ReportPlans>(CAPACITY_LIST_SIZE);
        plans.addAll(plansService.download_all2015_2016XsPlans());
        List<ReportPlans> myPlans = new ArrayList<ReportPlans>();
        List<MgrsProvinces> strs = plansService.selectMgrsProvinces();
        if(strs != null && strs.size() >= 1){
            for(MgrsProvinces s:strs){
                ReportPlans r = new ReportPlans();
                if(s.getMgr()!=null && s.getMgr().equals(user.getUser_name())){
                    r.setProvince(s.getProvince());
                    if(!myPlans.contains(r)){
                        myPlans.add(r);
                    }
                }
            }
        }
        plans.retainAll(myPlans);
        //把数据写入到Excel并返回文件路径和文件
        String filePath = ExcelUtils.exportCVS(plans, plansTitle);
        json.put("sucessful", 1);//关闭进度条
        json.put("filePath", "/servlet/FileDownServlet?url=" + filePath);//文件下载,请求Servlet
        ResonseUtils.writeResponseByJson(response, json);
        return null;
    }
    //下载2016-2017年经理自己省份销售流向
    @RequestMapping(value = "/download_2016_2017xsPlans_self.do")
    public JsonResult download_2016_2017xsPlans_self(HttpServletRequest request,HttpServletResponse response) {
        HttpSession session = request.getSession();
        User user = (User)session.getAttribute("user");
        JSONObject json = new JSONObject();
        //准备数据
        List<ReportPlans> plans = new ArrayList<ReportPlans>(CAPACITY_LIST_SIZE);
        plans.addAll(plansService.download_all2016_2017XsPlans());
        List<ReportPlans> myPlans = new ArrayList<ReportPlans>();
        List<MgrsProvinces> strs = plansService.selectMgrsProvinces();
        if(strs != null && strs.size() >= 1){
            for(MgrsProvinces s:strs){
                ReportPlans r = new ReportPlans();
                if(s.getMgr()!=null && s.getMgr().equals(user.getUser_name())){
                    r.setProvince(s.getProvince());
                    if(!myPlans.contains(r)){
                        myPlans.add(r);
                    }
                }
            }
        }
        plans.retainAll(myPlans);
        //把数据写入到Excel并返回文件路径和文件
        String filePath = ExcelUtils.exportCVS(plans, plansTitle);
        json.put("sucessful", 1);//关闭进度条
        json.put("filePath", "/servlet/FileDownServlet?url=" + filePath);//文件下载,请求Servlet
        ResonseUtils.writeResponseByJson(response, json);
        return null;
    }
    //下载2017-2018年经理自己省份销售流向
    @RequestMapping(value = "/download_2017_2018xsPlans_self.do")
    public JsonResult download_2017_2018xsPlans_self(HttpServletRequest request,HttpServletResponse response) {
        HttpSession session = request.getSession();
        User user = (User)session.getAttribute("user");
        JSONObject json = new JSONObject();
        //准备数据
        List<ReportPlans> plans = new ArrayList<ReportPlans>(CAPACITY_LIST_SIZE);
        plans.addAll(plansService.download_all2017_2018XsPlans());
        List<ReportPlans> myPlans = new ArrayList<ReportPlans>();
        List<MgrsProvinces> strs = plansService.selectMgrsProvinces();
        if(strs != null && strs.size() >= 1){
            for(MgrsProvinces s:strs){
                ReportPlans r = new ReportPlans();
                if(s.getMgr()!=null && s.getMgr().equals(user.getUser_name())){
                    r.setProvince(s.getProvince());
                    if(!myPlans.contains(r)){
                        myPlans.add(r);
                    }
                }
            }
        }
        plans.retainAll(myPlans);
        //把数据写入到Excel并返回文件路径和文件
        String filePath = ExcelUtils.exportCVS(plans, plansTitle);
        json.put("sucessful", 1);//关闭进度条
        json.put("filePath", "/servlet/FileDownServlet?url=" + filePath);//文件下载,请求Servlet
        ResonseUtils.writeResponseByJson(response, json);
        return null;
    }
    //经理自己省份连续2年销售---------------------end-------------------------

    //全国连续2年销售----------------------start-------------------------
    //下载2014-2015年全国销售流向
    @RequestMapping(value = "/download_all2014_2015XsPlans.do")
    public JsonResult download_all2014_2015XsPlans(HttpServletResponse response) {
        JSONObject json = new JSONObject();
        //准备数据
        List<ReportPlans> plans = new ArrayList<ReportPlans>(CAPACITY_LIST_SIZE);
        plans.addAll(plansService.download_all2014_2015XsPlans());
        //把数据写入到Excel并返回文件路径和文件
        String filePath = ExcelUtils.exportCVS(plans, plansTitle);
        json.put("sucessful", 1);//关闭进度条
        json.put("filePath", "/servlet/FileDownServlet?url=" + filePath);//文件下载,请求Servlet
        ResonseUtils.writeResponseByJson(response, json);
        return null;
    }
    //下载2015-2016年全国销售流向
    @RequestMapping(value = "/download_all2015_2016XsPlans.do")
    public JsonResult download_all2015_2016XsPlans(HttpServletResponse response) {
        JSONObject json = new JSONObject();
        //准备数据
        List<ReportPlans> plans = new ArrayList<ReportPlans>(CAPACITY_LIST_SIZE);
        plans.addAll(plansService.download_all2015_2016XsPlans());
        //把数据写入到Excel并返回文件路径和文件
        String filePath = ExcelUtils.exportCVS(plans, plansTitle);
        json.put("sucessful", 1);//关闭进度条
        json.put("filePath", "/servlet/FileDownServlet?url=" + filePath);//文件下载,请求Servlet
        ResonseUtils.writeResponseByJson(response, json);
        return null;
    }
    //下载2016-2017年全国销售流向
    @RequestMapping(value = "/download_all2016_2017XsPlans.do")
    public JsonResult download_all2016_2017XsPlans(HttpServletResponse response) {
        JSONObject json = new JSONObject();
        //准备数据
        List<ReportPlans> plans = new ArrayList<ReportPlans>(CAPACITY_LIST_SIZE);
        plans.addAll(plansService.download_all2016_2017XsPlans());
        //把数据写入到Excel并返回文件路径和文件
        String filePath = ExcelUtils.exportCVS(plans, plansTitle);
        json.put("sucessful", 1);//关闭进度条
        json.put("filePath", "/servlet/FileDownServlet?url=" + filePath);//文件下载,请求Servlet
        ResonseUtils.writeResponseByJson(response, json);
        return null;
    }
    //下载2017-2018年全国销售流向
    @RequestMapping(value = "/download_all2017_2018XsPlans.do")
    public JsonResult download_all2017_2018XsPlans(HttpServletResponse response) {
        JSONObject json = new JSONObject();
        //准备数据
        List<ReportPlans> plans = new ArrayList<ReportPlans>(CAPACITY_LIST_SIZE);
        plans.addAll(plansService.download_all2017_2018XsPlans());
        //把数据写入到Excel并返回文件路径和文件
        String filePath = ExcelUtils.exportCVS(plans, plansTitle);
        json.put("sucessful", 1);//关闭进度条
        json.put("filePath", "/servlet/FileDownServlet?url=" + filePath);//文件下载,请求Servlet
        ResonseUtils.writeResponseByJson(response, json);
        return null;
    }
    //全国连续2年销售----------------------end-------------------------


    //下载2018年纯销流向 自己省份的
    @RequestMapping(value = "/download_all2018CxPlans_self.do")
    public JsonResult download_all2018CxPlans_self(HttpServletResponse response,HttpServletRequest request) {
        HttpSession session = request.getSession();
        User user = (User)session.getAttribute("user");
        JSONObject json = new JSONObject();
        //准备数据
        List<ReportPlans> plans = plansService.download_all2018CxPlans();
        List<ReportPlans> myPlans = new ArrayList<ReportPlans>();
        List<MgrsProvinces> strs = plansService.selectMgrsProvinces();
        if(strs != null && strs.size() >= 1){
            for(MgrsProvinces s:strs){
                ReportPlans r = new ReportPlans();
                if(s.getMgr()!=null && s.getMgr().equals(user.getUser_name())){
                    r.setProvince(s.getProvince());
                    if(!myPlans.contains(r)){
                        myPlans.add(r);
                    }
                }
            }
        }
        plans.retainAll(myPlans);
        //把数据写入到Excel并返回文件路径和文件
        String filePath = ExcelUtils.exportCVS(plans, plansTitle);
        json.put("sucessful", 1);//关闭进度条
        json.put("filePath", "/servlet/FileDownServlet?url=" + filePath);//文件下载,请求Servlet
        ResonseUtils.writeResponseByJson(response, json);
        return null;
    }

    //下载2018年销售流向
    @RequestMapping(value = "/download_all2018XsPlans.do")
    public JsonResult download_all2018XsPlans(HttpServletResponse response) {
        JSONObject json = new JSONObject();
        //准备数据
        List<ReportPlans> plans = plansService.download_all2018XsPlans();
        //把数据写入到Excel并返回文件路径和文件
        String filePath = ExcelUtils.exportCVS(plans, plansTitle);
        json.put("sucessful", 1);//关闭进度条
        json.put("filePath", "/servlet/FileDownServlet?url=" + filePath);//文件下载,请求Servlet
        ResonseUtils.writeResponseByJson(response, json);
        return null;
    }
    //下载2018年销售流向 自己省份的
    @RequestMapping(value = "/download_all2018XsPlans_self.do")
    public JsonResult download_all2018XsPlans_self(HttpServletResponse response, HttpServletRequest request) {
        HttpSession session = request.getSession();
        User user = (User)session.getAttribute("user");
        JSONObject json = new JSONObject();
        //准备数据
        List<ReportPlans> plans = plansService.download_all2018XsPlans();
        List<ReportPlans> myPlans = new ArrayList<ReportPlans>();
        List<MgrsProvinces> strs = plansService.selectMgrsProvinces();
        if(strs != null && strs.size() >= 1){
            for(MgrsProvinces s:strs){
                ReportPlans r = new ReportPlans();
                if(s.getMgr()!=null && s.getMgr().equals(user.getUser_name())){
                    r.setProvince(s.getProvince());
                    if(!myPlans.contains(r)){
                        myPlans.add(r);
                    }
                }
            }
        }
        plans.retainAll(myPlans);
        //把数据写入到Excel并返回文件路径和文件
        String filePath = ExcelUtils.exportCVS(plans, plansTitle);
        json.put("sucessful", 1);//关闭进度条
        json.put("filePath", "/servlet/FileDownServlet?url=" + filePath);//文件下载,请求Servlet
        ResonseUtils.writeResponseByJson(response, json);
        return null;
    }
    //下载2018月均过1000盒的终端和区县 Q3 A 月均过1000盒的情况
    @RequestMapping(value = "/download_2018MonthPVG1000.do")
    public JsonResult download_2018MonthPVG1000(HttpServletResponse response) {
        JSONObject json = new JSONObject();
        //准备数据
        List<Terminal1000> terminals = plansService.download_2018MonthPVG1000Terminal();
        List<Country1000> countrys = plansService.download_2018MonthPVG1000Country();
        List<String> terminalNames = new ArrayList<String>();
        List<String> countryNames = new ArrayList<String>();
        for(Terminal1000 s:terminals){
            if(!terminalNames.contains(s.getTerminalQs())){
                terminalNames.add(s.getTerminalQs());
            }
        }
        for(Country1000 s:countrys){
            if(!countryNames.contains(s.getCountry())){
                countryNames.add(s.getCountry());
            }
        }

        List<MonthPVG1000View> plans = new ArrayList<MonthPVG1000View>();
        for(String s:terminalNames){
            float sum = 0;
            int month_start = 1;
            int month_end = 1;
            List<Integer> months = new ArrayList<Integer>();
            for(int i=0;i<terminals.size();i++){
                if(s.equals(terminals.get(i).getTerminalQs())){
                    sum+=terminals.get(i).getSumScount();//获取该终端所有的折合量求和
                    if(!months.contains(terminals.get(i).getMouth())){
                        months.add(terminals.get(i).getMouth());
                    }
                }
            }
            //获取开始月
            month_start = months.get(0);
            //获取结束月
            month_end = months.get(months.size()-1);
            
            //有效月
            int m = 1;
            if((month_end-month_start)>3) {
            	m = 3;
            } else {
            	m = Math.abs(month_end-month_start)+1;
            }
            float avg = sum/m;
            if(avg >= 1000){//月均超过1000盒
                MonthPVG1000View view = new MonthPVG1000View();
                view.setFenzu("终端");
                view.setTerminal_country(s);
                view.setSum(sum);
                view.setMonth(m);
                view.setAvg(avg);
                plans.add(view);
            }
        }
        for(String s:countryNames){
            float sum = 0;
            int month_start = 1;
            int month_end = 1;
            List<Integer> months = new ArrayList<Integer>();
            for(int i=0;i<countrys.size();i++){
                if(s.equals(countrys.get(i).getCountry())){
                    sum+=countrys.get(i).getSumScount();//获取该终端所有的折合量求和
                    if(!months.contains(countrys.get(i).getMouth())){
                        months.add(countrys.get(i).getMouth());
                    }
                }
            }
            //获取开始月
            month_start = months.get(0);
            //获取结束月
            month_end = months.get(months.size()-1);
            //有效月
            int m = 1;
            if((month_end-month_start)>3) {
            	m = 3;
            } else {
            	m = Math.abs(month_end-month_start)+1;
            }
            float avg = sum/m;
            if(avg >= 1000){//月均超过1000盒
                MonthPVG1000View view = new MonthPVG1000View();
                view.setFenzu("区县");
                view.setTerminal_country(s);
                view.setSum(sum);
                view.setMonth(m);
                view.setAvg(avg);
                plans.add(view);
            }
        }
        //把数据写入到Excel并返回文件路径和文件
        String filePath = ExcelUtils.exportCVS(plans, MonthPVG1000Title2018);
        json.put("sucessful", 1);//关闭进度条
        json.put("filePath", "/servlet/FileDownServlet?url=" + filePath);//文件下载,请求Servlet
        ResonseUtils.writeResponseByJson(response, json);
        return null;
    }
    //下载2017月均过1000盒的终端和区县
    @RequestMapping(value = "/download_2017MonthPVG1000.do")
    public JsonResult download_2017MonthPVG1000(HttpServletResponse response) {
        JSONObject json = new JSONObject();
        //准备数据
        List<Terminal1000> terminals = plansService.download_2017MonthPVG1000Terminal();
        List<Country1000> countrys = plansService.download_2017MonthPVG1000Country();
        List<String> terminalNames = new ArrayList<String>();
        List<String> countryNames = new ArrayList<String>();
        for(Terminal1000 s:terminals){
            if(!terminalNames.contains(s.getTerminalQs())){
                terminalNames.add(s.getTerminalQs());
            }
        }
        for(Country1000 s:countrys){
            if(!countryNames.contains(s.getCountry())){
                countryNames.add(s.getCountry());
            }
        }

        List<MonthPVG1000View> plans = new ArrayList<MonthPVG1000View>();
        for(String s:terminalNames){
            float sum = 0;
            int month_start = 1;
            int month_end = 1;
            List<Integer> months = new ArrayList<Integer>();
            for(int i=0;i<terminals.size();i++){
                if(s.equals(terminals.get(i).getTerminalQs())){
                    sum+=terminals.get(i).getSumScount();//获取该终端所有的折合量求和
                    if(!months.contains(terminals.get(i).getMouth())){
                        months.add(terminals.get(i).getMouth());
                    }
                }
            }
            //获取开始月
            month_start = months.get(0);
            //获取结束月
            month_end = months.get(months.size()-1);
            float avg = sum/(month_end-month_start+1);
            if(avg >= 1000){//月均超过1000盒
                MonthPVG1000View view = new MonthPVG1000View();
                view.setFenzu("终端");
                view.setTerminal_country(s);
                view.setSum(sum);
                view.setMonth((month_end-month_start+1));
                view.setAvg(avg);
                plans.add(view);
            }
        }
        for(String s:countryNames){
            float sum = 0;
            int month_start = 1;
            int month_end = 1;
            List<Integer> months = new ArrayList<Integer>();
            for(int i=0;i<countrys.size();i++){
                if(s.equals(countrys.get(i).getCountry())){
                    sum+=countrys.get(i).getSumScount();//获取该终端所有的折合量求和
                    if(!months.contains(countrys.get(i).getMouth())){
                        months.add(countrys.get(i).getMouth());
                    }
                }
            }
            //获取开始月
            month_start = months.get(0);
            //获取结束月
            month_end = months.get(months.size()-1);
            float avg = sum/(month_end-month_start+1);
            if(avg >= 1000){//月均超过1000盒
                MonthPVG1000View view = new MonthPVG1000View();
                view.setFenzu("区县");
                view.setTerminal_country(s);
                view.setSum(sum);
                view.setMonth((month_end-month_start+1));
                view.setAvg(avg);
                plans.add(view);
            }
        }
        //把数据写入到Excel并返回文件路径和文件
        String filePath = ExcelUtils.exportCVS(plans, MonthPVG1000Title2017);
        json.put("sucessful", 1);//关闭进度条
        json.put("filePath", "/servlet/FileDownServlet?url=" + filePath);//文件下载,请求Servlet
        ResonseUtils.writeResponseByJson(response, json);
        return null;
    }

    //下载2018月均过1000盒的好伙伴
    @RequestMapping(value = "/download_cx2018goodfriend1000.do")
    public JsonResult download_cx2018goodfriend1000(HttpServletResponse response) {
        JSONObject json = new JSONObject();
        //准备数据
        List<GoodFriend1000> daibaos = new ArrayList<GoodFriend1000>(5000);
        daibaos = plansService.download_cx2018goodfriend1000();
        List<String> goodfriends = new ArrayList<String>(500);
        for(GoodFriend1000 s:daibaos){
            if(!goodfriends.contains(s.getDaibiao())){
                goodfriends.add(s.getDaibiao());
            }
        }
        List<MonthPVG1000View> plans = new ArrayList<MonthPVG1000View>(500);
        for(String s:goodfriends){
            float sum = 0;
            int month_start = 1;
            int month_end = 1;
            List<Integer> months = new ArrayList<Integer>();
            for(int i=0;i<daibaos.size();i++){
                if(s.equals(daibaos.get(i).getDaibiao())){
                    sum+=daibaos.get(i).getSumScount();//获取该终端所有的折合量求和
                    if(!months.contains(daibaos.get(i).getMouth())){
                        months.add(daibaos.get(i).getMouth());
                    }
                }
            }
            if(months.size()>=1){
                //获取开始月
                month_start = months.get(0);
                //获取结束月
                month_end = months.get(months.size()-1);
            }
            float avg = sum/(month_end-month_start+1);
            if(avg >= 1000){//月均超过1000盒
                MonthPVG1000View view = new MonthPVG1000View();
                view.setFenzu("好伙伴");
                view.setTerminal_country(s);
                view.setSum(sum);
                view.setMonth((month_end-month_start+1));
                view.setAvg(avg);
                plans.add(view);
            }
        }
        //把数据写入到Excel并返回文件路径和文件
        String filePath = ExcelUtils.exportCVS(plans, MonthPVG1000Title2018GF);
        json.put("sucessful", 1);//关闭进度条
        json.put("filePath", "/servlet/FileDownServlet?url=" + filePath);//文件下载,请求Servlet
        ResonseUtils.writeResponseByJson(response, json);
        return null;
    }
    
    
    
    //下载2018年新开发终端流向情况
    @RequestMapping(value = "/download_2018_cxPlans_newDev.do")
    public JsonResult download_2018_cxPlans_newDev(HttpServletResponse response) {
        JSONObject json = new JSONObject();
        //准备数据 2018所有纯销和另付流向
        List<ReportPlansTerminal> plans = plansService.download_all2018CxPlans_terminal();
        //准备数据 动态前6个月的流向
        List<ReportPlansTerminal> myPlans = plansService.download_allP6CxPlans();
        
        plans.removeAll(myPlans);
        //把数据写入到Excel并返回文件路径和文件
        String filePath = ExcelUtils.exportCVS(plans, plansTitle);
        json.put("sucessful", 1);//关闭进度条
        json.put("filePath", "/servlet/FileDownServlet?url=" + filePath);//文件下载,请求Servlet
        ResonseUtils.writeResponseByJson(response, json);
        return null;
    }
    //下载2018年2月保有终端、新开发终端、丢失终端情况
    @RequestMapping(value = "/download_2018cxTPP2.do")
    public JsonResult download_2018cxTPP2(HttpServletResponse response) {
    	JSONObject json = new JSONObject();
    	//准备数据
    	List<TPPScountData> TPPScountData1s = new ArrayList<TPPScountData>(10000);
    	TPPScountData1s = plansService.download_2018cxTPP1();//1月保有终端
    	List<TPPScountData> TPPScountData2s = new ArrayList<TPPScountData>(10000);
    	List<TPPScountData> TPPScountData2sBak = new ArrayList<TPPScountData>(10000);
    	TPPScountData2s = plansService.download_2018cxTPP2();//2月保有终端
    	TPPScountData2sBak.addAll(TPPScountData2s);
    	
    	List<TPPScountView> plans = new ArrayList<TPPScountView>(1000);
    	TPPScountData2s.removeAll(TPPScountData1s);
    	if(TPPScountData2s.size() >=1){//新增了终端
    		for(TPPScountData s:TPPScountData2s){
    			TPPScountView v = new TPPScountView();
    			v.setMgr(s.getMgr());
    			v.setDaqu(s.getDaqu());
    			v.setSpace(s.getSpace());
    			v.setProvince(s.getProvince());
    			v.setCity(s.getCity());
    			v.setCounty(s.getCounty());
    			v.setQudao(s.getQudao());
    			v.setTerminalQs(s.getTerminalQs());
    			v.setProduct(s.getProduct());
    			v.setPack(s.getPack());
    			v.setSumScount(s.getSumScount());
    			v.setFenzu("新增终端");
    			plans.add(v);
    		}
    	}
    	TPPScountData1s.removeAll(TPPScountData2sBak);
    	if(TPPScountData1s.size() >=1){//丢失了终端
    		for(TPPScountData s:TPPScountData1s){
    			TPPScountView v = new TPPScountView();
    			v.setMgr(s.getMgr());
    			v.setDaqu(s.getDaqu());
    			v.setSpace(s.getSpace());
    			v.setProvince(s.getProvince());
    			v.setCity(s.getCity());
    			v.setCounty(s.getCounty());
    			v.setQudao(s.getQudao());
    			v.setTerminalQs(s.getTerminalQs());
    			v.setProduct(s.getProduct());
    			v.setPack(s.getPack());
    			v.setSumScount(s.getSumScount());
    			v.setFenzu("丢失终端");
    			plans.add(v);
    		}
    	}
    	//把数据写入到Excel并返回文件路径和文件
    	String filePath = ExcelUtils.exportCVS(plans, newTerminalAndLosts);
    	json.put("sucessful", 1);//关闭进度条
    	json.put("filePath", "/servlet/FileDownServlet?url=" + filePath);//文件下载,请求Servlet
    	ResonseUtils.writeResponseByJson(response, json);
    	return null;
    }
    //下载2018年3月保有终端、新开发终端、丢失终端情况
    @RequestMapping(value = "/download_2018cxTPP3.do")
    public JsonResult download_2018cxTPP3(HttpServletResponse response) {
        JSONObject json = new JSONObject();
        //准备数据
        List<TPPScountData> TPPScountData1s = new ArrayList<TPPScountData>(10000);
        TPPScountData1s = plansService.download_2018cxTPP2();//2月保有终端
        List<TPPScountData> TPPScountData2s = new ArrayList<TPPScountData>(10000);
        List<TPPScountData> TPPScountData2sBak = new ArrayList<TPPScountData>(10000);
        TPPScountData2s = plansService.download_2018cxTPP3();//3月保有终端
        TPPScountData2sBak.addAll(TPPScountData2s);

        List<TPPScountView> plans = new ArrayList<TPPScountView>(1000);
        TPPScountData2s.removeAll(TPPScountData1s);
        if(TPPScountData2s.size() >=1){//新增了终端
            for(TPPScountData s:TPPScountData2s){
                TPPScountView v = new TPPScountView();
                v.setMgr(s.getMgr());
                v.setDaqu(s.getDaqu());
                v.setSpace(s.getSpace());
                v.setProvince(s.getProvince());
                v.setCity(s.getCity());
                v.setCounty(s.getCounty());
                v.setQudao(s.getQudao());
                v.setTerminalQs(s.getTerminalQs());
                v.setProduct(s.getProduct());
                v.setPack(s.getPack());
                v.setSumScount(s.getSumScount());
                v.setFenzu("新增终端");
                plans.add(v);
            }
        }
        TPPScountData1s.removeAll(TPPScountData2sBak);
        if(TPPScountData1s.size() >=1){//丢失了终端
            for(TPPScountData s:TPPScountData1s){
                TPPScountView v = new TPPScountView();
                v.setMgr(s.getMgr());
                v.setDaqu(s.getDaqu());
                v.setSpace(s.getSpace());
                v.setProvince(s.getProvince());
                v.setCity(s.getCity());
                v.setCounty(s.getCounty());
                v.setQudao(s.getQudao());
                v.setTerminalQs(s.getTerminalQs());
                v.setProduct(s.getProduct());
                v.setPack(s.getPack());
                v.setSumScount(s.getSumScount());
                v.setFenzu("丢失终端");
                plans.add(v);
            }
        }
        //把数据写入到Excel并返回文件路径和文件
        String filePath = ExcelUtils.exportCVS(plans, newTerminalAndLosts);
        json.put("sucessful", 1);//关闭进度条
        json.put("filePath", "/servlet/FileDownServlet?url=" + filePath);//文件下载,请求Servlet
        ResonseUtils.writeResponseByJson(response, json);
        return null;
    }
    //下载2018年4月保有终端、新开发终端、丢失终端情况
    @RequestMapping(value = "/download_2018cxTPP4.do")
    public JsonResult download_2018cxTPP4(HttpServletResponse response) {
        JSONObject json = new JSONObject();
        //准备数据
        List<TPPScountData> TPPScountData1s = new ArrayList<TPPScountData>(10000);
        TPPScountData1s = plansService.download_2018cxTPP3();//3月保有终端
        List<TPPScountData> TPPScountData2s = new ArrayList<TPPScountData>(10000);
        List<TPPScountData> TPPScountData2sBak = new ArrayList<TPPScountData>(10000);
        TPPScountData2s = plansService.download_2018cxTPP4();//4月保有终端
        TPPScountData2sBak.addAll(TPPScountData2s);

        List<TPPScountView> plans = new ArrayList<TPPScountView>(1000);
        TPPScountData2s.removeAll(TPPScountData1s);
        if(TPPScountData2s.size() >=1){//新增了终端
            for(TPPScountData s:TPPScountData2s){
                TPPScountView v = new TPPScountView();
                v.setMgr(s.getMgr());
                v.setDaqu(s.getDaqu());
                v.setSpace(s.getSpace());
                v.setProvince(s.getProvince());
                v.setCity(s.getCity());
                v.setCounty(s.getCounty());
                v.setQudao(s.getQudao());
                v.setTerminalQs(s.getTerminalQs());
                v.setProduct(s.getProduct());
                v.setPack(s.getPack());
                v.setSumScount(s.getSumScount());
                v.setFenzu("新增终端");
                plans.add(v);
            }
        }
        TPPScountData1s.removeAll(TPPScountData2sBak);
        if(TPPScountData1s.size() >=1){//丢失了终端
            for(TPPScountData s:TPPScountData1s){
                TPPScountView v = new TPPScountView();
                v.setMgr(s.getMgr());
                v.setDaqu(s.getDaqu());
                v.setSpace(s.getSpace());
                v.setProvince(s.getProvince());
                v.setCity(s.getCity());
                v.setCounty(s.getCounty());
                v.setQudao(s.getQudao());
                v.setTerminalQs(s.getTerminalQs());
                v.setProduct(s.getProduct());
                v.setPack(s.getPack());
                v.setSumScount(s.getSumScount());
                v.setFenzu("丢失终端");
                plans.add(v);
            }
        }
        //把数据写入到Excel并返回文件路径和文件
        String filePath = ExcelUtils.exportCVS(plans, newTerminalAndLosts);
        json.put("sucessful", 1);//关闭进度条
        json.put("filePath", "/servlet/FileDownServlet?url=" + filePath);//文件下载,请求Servlet
        ResonseUtils.writeResponseByJson(response, json);
        return null;
    }
    //下载2018年5月保有终端、新开发终端、丢失终端情况
    @RequestMapping(value = "/download_2018cxTPP5.do")
    public JsonResult download_2018cxTPP5(HttpServletResponse response) {
        JSONObject json = new JSONObject();
        //准备数据
        List<TPPScountData> TPPScountData1s = new ArrayList<TPPScountData>(10000);
        TPPScountData1s = plansService.download_2018cxTPP4();//4月保有终端
        List<TPPScountData> TPPScountData2s = new ArrayList<TPPScountData>(10000);
        List<TPPScountData> TPPScountData2sBak = new ArrayList<TPPScountData>(10000);
        TPPScountData2s = plansService.download_2018cxTPP5();//5月保有终端
        TPPScountData2sBak.addAll(TPPScountData2s);

        List<TPPScountView> plans = new ArrayList<TPPScountView>(1000);
        TPPScountData2s.removeAll(TPPScountData1s);
        if(TPPScountData2s.size() >=1){//新增了终端
            for(TPPScountData s:TPPScountData2s){
                TPPScountView v = new TPPScountView();
                v.setMgr(s.getMgr());
                v.setDaqu(s.getDaqu());
                v.setSpace(s.getSpace());
                v.setProvince(s.getProvince());
                v.setCity(s.getCity());
                v.setCounty(s.getCounty());
                v.setQudao(s.getQudao());
                v.setTerminalQs(s.getTerminalQs());
                v.setProduct(s.getProduct());
                v.setPack(s.getPack());
                v.setSumScount(s.getSumScount());
                v.setFenzu("新增终端");
                plans.add(v);
            }
        }
        TPPScountData1s.removeAll(TPPScountData2sBak);
        if(TPPScountData1s.size() >=1){//丢失了终端
            for(TPPScountData s:TPPScountData1s){
                TPPScountView v = new TPPScountView();
                v.setMgr(s.getMgr());
                v.setDaqu(s.getDaqu());
                v.setSpace(s.getSpace());
                v.setProvince(s.getProvince());
                v.setCity(s.getCity());
                v.setCounty(s.getCounty());
                v.setQudao(s.getQudao());
                v.setTerminalQs(s.getTerminalQs());
                v.setProduct(s.getProduct());
                v.setPack(s.getPack());
                v.setSumScount(s.getSumScount());
                v.setFenzu("丢失终端");
                plans.add(v);
            }
        }
        //把数据写入到Excel并返回文件路径和文件
        String filePath = ExcelUtils.exportCVS(plans, newTerminalAndLosts);
        json.put("sucessful", 1);//关闭进度条
        json.put("filePath", "/servlet/FileDownServlet?url=" + filePath);//文件下载,请求Servlet
        ResonseUtils.writeResponseByJson(response, json);
        return null;
    }
    //下载2018年6月保有终端、新开发终端、丢失终端情况
    @RequestMapping(value = "/download_2018cxTPP6.do")
    public JsonResult download_2018cxTPP6(HttpServletResponse response) {
        JSONObject json = new JSONObject();
        //准备数据
        List<TPPScountData> TPPScountData1s = new ArrayList<TPPScountData>(10000);
        TPPScountData1s = plansService.download_2018cxTPP5();//5月保有终端
        List<TPPScountData> TPPScountData2s = new ArrayList<TPPScountData>(10000);
        List<TPPScountData> TPPScountData2sBak = new ArrayList<TPPScountData>(10000);
        TPPScountData2s = plansService.download_2018cxTPP6();//6月保有终端
        TPPScountData2sBak.addAll(TPPScountData2s);

        List<TPPScountView> plans = new ArrayList<TPPScountView>(1000);
        TPPScountData2s.removeAll(TPPScountData1s);
        if(TPPScountData2s.size() >=1){//新增了终端
            for(TPPScountData s:TPPScountData2s){
                TPPScountView v = new TPPScountView();
                v.setMgr(s.getMgr());
                v.setDaqu(s.getDaqu());
                v.setSpace(s.getSpace());
                v.setProvince(s.getProvince());
                v.setCity(s.getCity());
                v.setCounty(s.getCounty());
                v.setQudao(s.getQudao());
                v.setTerminalQs(s.getTerminalQs());
                v.setProduct(s.getProduct());
                v.setPack(s.getPack());
                v.setSumScount(s.getSumScount());
                v.setFenzu("新增终端");
                plans.add(v);
            }
        }
        TPPScountData1s.removeAll(TPPScountData2sBak);
        if(TPPScountData1s.size() >=1){//丢失了终端
            for(TPPScountData s:TPPScountData1s){
                TPPScountView v = new TPPScountView();
                v.setMgr(s.getMgr());
                v.setDaqu(s.getDaqu());
                v.setSpace(s.getSpace());
                v.setProvince(s.getProvince());
                v.setCity(s.getCity());
                v.setCounty(s.getCounty());
                v.setQudao(s.getQudao());
                v.setTerminalQs(s.getTerminalQs());
                v.setProduct(s.getProduct());
                v.setPack(s.getPack());
                v.setSumScount(s.getSumScount());
                v.setFenzu("丢失终端");
                plans.add(v);
            }
        }
        //把数据写入到Excel并返回文件路径和文件
        String filePath = ExcelUtils.exportCVS(plans, newTerminalAndLosts);
        json.put("sucessful", 1);//关闭进度条
        json.put("filePath", "/servlet/FileDownServlet?url=" + filePath);//文件下载,请求Servlet
        ResonseUtils.writeResponseByJson(response, json);
        return null;
    }
    //下载2018年7月保有终端、新开发终端、丢失终端情况
    @RequestMapping(value = "/download_2018cxTPP7.do")
    public JsonResult download_2018cxTPP7(HttpServletResponse response) {
        JSONObject json = new JSONObject();
        //准备数据
        List<TPPScountData> TPPScountData1s = new ArrayList<TPPScountData>(10000);
        TPPScountData1s = plansService.download_2018cxTPP6();//6月保有终端
        List<TPPScountData> TPPScountData2s = new ArrayList<TPPScountData>(10000);
        List<TPPScountData> TPPScountData2sBak = new ArrayList<TPPScountData>(10000);
        TPPScountData2s = plansService.download_2018cxTPP7();//7月保有终端
        TPPScountData2sBak.addAll(TPPScountData2s);

        List<TPPScountView> plans = new ArrayList<TPPScountView>(1000);
        TPPScountData2s.removeAll(TPPScountData1s);
        if(TPPScountData2s.size() >=1){//新增了终端
            for(TPPScountData s:TPPScountData2s){
                TPPScountView v = new TPPScountView();
                v.setMgr(s.getMgr());
                v.setDaqu(s.getDaqu());
                v.setSpace(s.getSpace());
                v.setProvince(s.getProvince());
                v.setCity(s.getCity());
                v.setCounty(s.getCounty());
                v.setQudao(s.getQudao());
                v.setTerminalQs(s.getTerminalQs());
                v.setProduct(s.getProduct());
                v.setPack(s.getPack());
                v.setSumScount(s.getSumScount());
                v.setFenzu("新增终端");
                plans.add(v);
            }
        }
        TPPScountData1s.removeAll(TPPScountData2sBak);
        if(TPPScountData1s.size() >=1){//丢失了终端
            for(TPPScountData s:TPPScountData1s){
                TPPScountView v = new TPPScountView();
                v.setMgr(s.getMgr());
                v.setDaqu(s.getDaqu());
                v.setSpace(s.getSpace());
                v.setProvince(s.getProvince());
                v.setCity(s.getCity());
                v.setCounty(s.getCounty());
                v.setQudao(s.getQudao());
                v.setTerminalQs(s.getTerminalQs());
                v.setProduct(s.getProduct());
                v.setPack(s.getPack());
                v.setSumScount(s.getSumScount());
                v.setFenzu("丢失终端");
                plans.add(v);
            }
        }
        //把数据写入到Excel并返回文件路径和文件
        String filePath = ExcelUtils.exportCVS(plans, newTerminalAndLosts);
        json.put("sucessful", 1);//关闭进度条
        json.put("filePath", "/servlet/FileDownServlet?url=" + filePath);//文件下载,请求Servlet
        ResonseUtils.writeResponseByJson(response, json);
        return null;
    }
    //下载2018年8月保有终端、新开发终端、丢失终端情况
    @RequestMapping(value = "/download_2018cxTPP8.do")
    public JsonResult download_2018cxTPP8(HttpServletResponse response) {
        JSONObject json = new JSONObject();
        //准备数据
        List<TPPScountData> TPPScountData1s = new ArrayList<TPPScountData>(10000);
        TPPScountData1s = plansService.download_2018cxTPP7();//7月保有终端
        List<TPPScountData> TPPScountData2s = new ArrayList<TPPScountData>(10000);
        List<TPPScountData> TPPScountData2sBak = new ArrayList<TPPScountData>(10000);
        TPPScountData2s = plansService.download_2018cxTPP8();//8月保有终端
        TPPScountData2sBak.addAll(TPPScountData2s);

        List<TPPScountView> plans = new ArrayList<TPPScountView>(1000);
        TPPScountData2s.removeAll(TPPScountData1s);
        if(TPPScountData2s.size() >=1){//新增了终端
            for(TPPScountData s:TPPScountData2s){
                TPPScountView v = new TPPScountView();
                v.setMgr(s.getMgr());
                v.setDaqu(s.getDaqu());
                v.setSpace(s.getSpace());
                v.setProvince(s.getProvince());
                v.setCity(s.getCity());
                v.setCounty(s.getCounty());
                v.setQudao(s.getQudao());
                v.setTerminalQs(s.getTerminalQs());
                v.setProduct(s.getProduct());
                v.setPack(s.getPack());
                v.setSumScount(s.getSumScount());
                v.setFenzu("新增终端");
                plans.add(v);
            }
        }
        TPPScountData1s.removeAll(TPPScountData2sBak);
        if(TPPScountData1s.size() >=1){//丢失了终端
            for(TPPScountData s:TPPScountData1s){
                TPPScountView v = new TPPScountView();
                v.setMgr(s.getMgr());
                v.setDaqu(s.getDaqu());
                v.setSpace(s.getSpace());
                v.setProvince(s.getProvince());
                v.setCity(s.getCity());
                v.setCounty(s.getCounty());
                v.setQudao(s.getQudao());
                v.setTerminalQs(s.getTerminalQs());
                v.setProduct(s.getProduct());
                v.setPack(s.getPack());
                v.setSumScount(s.getSumScount());
                v.setFenzu("丢失终端");
                plans.add(v);
            }
        }
        //把数据写入到Excel并返回文件路径和文件
        String filePath = ExcelUtils.exportCVS(plans, newTerminalAndLosts);
        json.put("sucessful", 1);//关闭进度条
        json.put("filePath", "/servlet/FileDownServlet?url=" + filePath);//文件下载,请求Servlet
        ResonseUtils.writeResponseByJson(response, json);
        return null;
    }
    //下载2018年9月保有终端、新开发终端、丢失终端情况
    @RequestMapping(value = "/download_2018cxTPP9.do")
    public JsonResult download_2018cxTPP9(HttpServletResponse response) {
        JSONObject json = new JSONObject();
        //准备数据
        List<TPPScountData> TPPScountData1s = new ArrayList<TPPScountData>(10000);
        TPPScountData1s = plansService.download_2018cxTPP8();//8月保有终端
        List<TPPScountData> TPPScountData2s = new ArrayList<TPPScountData>(10000);
        List<TPPScountData> TPPScountData2sBak = new ArrayList<TPPScountData>(10000);
        TPPScountData2s = plansService.download_2018cxTPP9();//9月保有终端
        TPPScountData2sBak.addAll(TPPScountData2s);

        List<TPPScountView> plans = new ArrayList<TPPScountView>(1000);
        TPPScountData2s.removeAll(TPPScountData1s);
        if(TPPScountData2s.size() >=1){//新增了终端
            for(TPPScountData s:TPPScountData2s){
                TPPScountView v = new TPPScountView();
                v.setMgr(s.getMgr());
                v.setDaqu(s.getDaqu());
                v.setSpace(s.getSpace());
                v.setProvince(s.getProvince());
                v.setCity(s.getCity());
                v.setCounty(s.getCounty());
                v.setQudao(s.getQudao());
                v.setTerminalQs(s.getTerminalQs());
                v.setProduct(s.getProduct());
                v.setPack(s.getPack());
                v.setSumScount(s.getSumScount());
                v.setFenzu("新增终端");
                plans.add(v);
            }
        }
        TPPScountData1s.removeAll(TPPScountData2sBak);
        if(TPPScountData1s.size() >=1){//丢失了终端
            for(TPPScountData s:TPPScountData1s){
                TPPScountView v = new TPPScountView();
                v.setMgr(s.getMgr());
                v.setDaqu(s.getDaqu());
                v.setSpace(s.getSpace());
                v.setProvince(s.getProvince());
                v.setCity(s.getCity());
                v.setCounty(s.getCounty());
                v.setQudao(s.getQudao());
                v.setTerminalQs(s.getTerminalQs());
                v.setProduct(s.getProduct());
                v.setPack(s.getPack());
                v.setSumScount(s.getSumScount());
                v.setFenzu("丢失终端");
                plans.add(v);
            }
        }
        //把数据写入到Excel并返回文件路径和文件
        String filePath = ExcelUtils.exportCVS(plans, newTerminalAndLosts);
        json.put("sucessful", 1);//关闭进度条
        json.put("filePath", "/servlet/FileDownServlet?url=" + filePath);//文件下载,请求Servlet
        ResonseUtils.writeResponseByJson(response, json);
        return null;
    }
    //下载2018年10月保有终端、新开发终端、丢失终端情况
    @RequestMapping(value = "/download_2018cxTPP10.do")
    public JsonResult download_2018cxTPP10(HttpServletResponse response) {
        JSONObject json = new JSONObject();
        //准备数据
        List<TPPScountData> TPPScountData1s = new ArrayList<TPPScountData>(10000);
        TPPScountData1s = plansService.download_2018cxTPP9();//9月保有终端
        List<TPPScountData> TPPScountData2s = new ArrayList<TPPScountData>(10000);
        List<TPPScountData> TPPScountData2sBak = new ArrayList<TPPScountData>(10000);
        TPPScountData2s = plansService.download_2018cxTPP10();//10月保有终端
        TPPScountData2sBak.addAll(TPPScountData2s);

        List<TPPScountView> plans = new ArrayList<TPPScountView>(1000);
        TPPScountData2s.removeAll(TPPScountData1s);
        if(TPPScountData2s.size() >=1){//新增了终端
            for(TPPScountData s:TPPScountData2s){
                TPPScountView v = new TPPScountView();
                v.setMgr(s.getMgr());
                v.setDaqu(s.getDaqu());
                v.setSpace(s.getSpace());
                v.setProvince(s.getProvince());
                v.setCity(s.getCity());
                v.setCounty(s.getCounty());
                v.setQudao(s.getQudao());
                v.setTerminalQs(s.getTerminalQs());
                v.setProduct(s.getProduct());
                v.setPack(s.getPack());
                v.setSumScount(s.getSumScount());
                v.setFenzu("新增终端");
                plans.add(v);
            }
        }
        TPPScountData1s.removeAll(TPPScountData2sBak);
        if(TPPScountData1s.size() >=1){//丢失了终端
            for(TPPScountData s:TPPScountData1s){
                TPPScountView v = new TPPScountView();
                v.setMgr(s.getMgr());
                v.setDaqu(s.getDaqu());
                v.setSpace(s.getSpace());
                v.setProvince(s.getProvince());
                v.setCity(s.getCity());
                v.setCounty(s.getCounty());
                v.setQudao(s.getQudao());
                v.setTerminalQs(s.getTerminalQs());
                v.setProduct(s.getProduct());
                v.setPack(s.getPack());
                v.setSumScount(s.getSumScount());
                v.setFenzu("丢失终端");
                plans.add(v);
            }
        }
        //把数据写入到Excel并返回文件路径和文件
        String filePath = ExcelUtils.exportCVS(plans, newTerminalAndLosts);
        json.put("sucessful", 1);//关闭进度条
        json.put("filePath", "/servlet/FileDownServlet?url=" + filePath);//文件下载,请求Servlet
        ResonseUtils.writeResponseByJson(response, json);
        return null;
    }
    //下载2018年11月保有终端、新开发终端、丢失终端情况
    @RequestMapping(value = "/download_2018cxTPP11.do")
    public JsonResult download_2018cxTPP11(HttpServletResponse response) {
        JSONObject json = new JSONObject();
        //准备数据
        List<TPPScountData> TPPScountData1s = new ArrayList<TPPScountData>(10000);
        TPPScountData1s = plansService.download_2018cxTPP10();//10月保有终端
        List<TPPScountData> TPPScountData2s = new ArrayList<TPPScountData>(10000);
        List<TPPScountData> TPPScountData2sBak = new ArrayList<TPPScountData>(10000);
        TPPScountData2s = plansService.download_2018cxTPP11();//11月保有终端
        TPPScountData2sBak.addAll(TPPScountData2s);

        List<TPPScountView> plans = new ArrayList<TPPScountView>(1000);
        TPPScountData2s.removeAll(TPPScountData1s);
        if(TPPScountData2s.size() >=1){//新增了终端
            for(TPPScountData s:TPPScountData2s){
                TPPScountView v = new TPPScountView();
                v.setMgr(s.getMgr());
                v.setDaqu(s.getDaqu());
                v.setSpace(s.getSpace());
                v.setProvince(s.getProvince());
                v.setCity(s.getCity());
                v.setCounty(s.getCounty());
                v.setQudao(s.getQudao());
                v.setTerminalQs(s.getTerminalQs());
                v.setProduct(s.getProduct());
                v.setPack(s.getPack());
                v.setSumScount(s.getSumScount());
                v.setFenzu("新增终端");
                plans.add(v);
            }
        }
        TPPScountData1s.removeAll(TPPScountData2sBak);
        if(TPPScountData1s.size() >=1){//丢失了终端
            for(TPPScountData s:TPPScountData1s){
                TPPScountView v = new TPPScountView();
                v.setMgr(s.getMgr());
                v.setDaqu(s.getDaqu());
                v.setSpace(s.getSpace());
                v.setProvince(s.getProvince());
                v.setCity(s.getCity());
                v.setCounty(s.getCounty());
                v.setQudao(s.getQudao());
                v.setTerminalQs(s.getTerminalQs());
                v.setProduct(s.getProduct());
                v.setPack(s.getPack());
                v.setSumScount(s.getSumScount());
                v.setFenzu("丢失终端");
                plans.add(v);
            }
        }
        //把数据写入到Excel并返回文件路径和文件
        String filePath = ExcelUtils.exportCVS(plans, newTerminalAndLosts);
        json.put("sucessful", 1);//关闭进度条
        json.put("filePath", "/servlet/FileDownServlet?url=" + filePath);//文件下载,请求Servlet
        ResonseUtils.writeResponseByJson(response, json);
        return null;
    }
    //下载2018年12月保有终端、新开发终端、丢失终端情况
    @RequestMapping(value = "/download_2018cxTPP12.do")
    public JsonResult download_2018cxTPP12(HttpServletResponse response) {
        JSONObject json = new JSONObject();
        //准备数据
        List<TPPScountData> TPPScountData1s = new ArrayList<TPPScountData>(10000);
        TPPScountData1s = plansService.download_2018cxTPP11();//11月保有终端
        List<TPPScountData> TPPScountData2s = new ArrayList<TPPScountData>(10000);
        List<TPPScountData> TPPScountData2sBak = new ArrayList<TPPScountData>(10000);
        TPPScountData2s = plansService.download_2018cxTPP12();//12月保有终端
        TPPScountData2sBak.addAll(TPPScountData2s);

        List<TPPScountView> plans = new ArrayList<TPPScountView>(1000);
        TPPScountData2s.removeAll(TPPScountData1s);
        if(TPPScountData2s.size() >=1){//新增了终端
            for(TPPScountData s:TPPScountData2s){
                TPPScountView v = new TPPScountView();
                v.setMgr(s.getMgr());
                v.setDaqu(s.getDaqu());
                v.setSpace(s.getSpace());
                v.setProvince(s.getProvince());
                v.setCity(s.getCity());
                v.setCounty(s.getCounty());
                v.setQudao(s.getQudao());
                v.setTerminalQs(s.getTerminalQs());
                v.setProduct(s.getProduct());
                v.setPack(s.getPack());
                v.setSumScount(s.getSumScount());
                v.setFenzu("新增终端");
                plans.add(v);
            }
        }
        TPPScountData1s.removeAll(TPPScountData2sBak);
        if(TPPScountData1s.size() >=1){//丢失了终端
            for(TPPScountData s:TPPScountData1s){
                TPPScountView v = new TPPScountView();
                v.setMgr(s.getMgr());
                v.setDaqu(s.getDaqu());
                v.setSpace(s.getSpace());
                v.setProvince(s.getProvince());
                v.setCity(s.getCity());
                v.setCounty(s.getCounty());
                v.setQudao(s.getQudao());
                v.setTerminalQs(s.getTerminalQs());
                v.setProduct(s.getProduct());
                v.setPack(s.getPack());
                v.setSumScount(s.getSumScount());
                v.setFenzu("丢失终端");
                plans.add(v);
            }
        }
        //把数据写入到Excel并返回文件路径和文件
        String filePath = ExcelUtils.exportCVS(plans, newTerminalAndLosts);
        json.put("sucessful", 1);//关闭进度条
        json.put("filePath", "/servlet/FileDownServlet?url=" + filePath);//文件下载,请求Servlet
        ResonseUtils.writeResponseByJson(response, json);
        return null;
    }


    //下载2018渠道和省份
    @RequestMapping(value = "/download_2018qudaoAndProvice.do")
    public JsonResult download_2018qudaoAndProvice(HttpServletResponse response) {
        JSONObject json = new JSONObject();
        List<QudaoProvinceData> plans = plansService.download_2018qudaoAndProvice();
        //获取独立的渠道
        List<String> qudaos = new ArrayList<String>();
        //获取独立的省份
        List<String> provices = new ArrayList<String>();
        for (QudaoProvinceData s : plans) {
            if (!qudaos.contains(s.getQudao())) {
                qudaos.add(s.getQudao());
            }
            if (!provices.contains(s.getProvince())) {
                provices.add(s.getProvince());
            }
        }
        //准备下载数据
        List<QudaoProvinceView> list = new ArrayList<QudaoProvinceView>();
        //列汇总
        int m1=0,m2=0,m3=0,m4=0,m5=0,m6=0,m7=0,m8=0,m9=0,m10=0,m11=0,m12=0,rowSum=0;

        for (String q : qudaos) {
            QudaoProvinceView viewSum = new QudaoProvinceView();
            for (String s : provices) {
                QudaoProvinceView view = new QudaoProvinceView();
                for (QudaoProvinceData v : plans) {
                    if (q.equals(v.getQudao())) {
                        if (s.equals(v.getProvince())) {
                            if(view.getQudao() == null){
                                view.setQudao(v.getQudao());
                            }
                            if(view.getProvice() == null) {
                                view.setProvice(v.getProvince());
                            }
                            if(v.getMonth().equals("01")){view.setM1(v.getSumScount());}
                            if(v.getMonth().equals("02")){view.setM2(v.getSumScount());}
                            if(v.getMonth().equals("03")){view.setM3(v.getSumScount());}
                            if(v.getMonth().equals("04")){view.setM4(v.getSumScount());}
                            if(v.getMonth().equals("05")){view.setM5(v.getSumScount());}
                            if(v.getMonth().equals("06")){view.setM6(v.getSumScount());}
                            if(v.getMonth().equals("07")){view.setM7(v.getSumScount());}
                            if(v.getMonth().equals("08")){view.setM8(v.getSumScount());}
                            if(v.getMonth().equals("09")){view.setM9(v.getSumScount());}
                            if(v.getMonth().equals("10")){view.setM10(v.getSumScount());}
                            if(v.getMonth().equals("11")){view.setM11(v.getSumScount());}
                            if(v.getMonth().equals("12")){view.setM12(v.getSumScount());}
                        }
                    }
                }
                view.setRowSum(view.getM1()+view.getM2()+view.getM3()+view.getM4()+view.getM5()+view.getM6()+view.getM7()+view.getM8()+view.getM9()+view.getM10()+view.getM11()+view.getM12());
                if(view.getQudao()!=null&&view.getProvice()!=null){
                    list.add(view);
                    //列汇总
                    m1+=view.getM1(); m2+=view.getM2(); m3+=view.getM3(); m4+=view.getM4(); m5+=view.getM5(); m6+=view.getM6(); m7+=view.getM7(); m8+=view.getM8(); m9+=view.getM9(); m10+=view.getM10(); m11+=view.getM11(); m12+=view.getM12();
                    view=null;
                }
            }
            rowSum=m1+m2+m3+m4+m5+m6+m7+m8+m9+m10+m11+m12;
            viewSum.setQudao(q+"汇总");
            viewSum.setProvice("");
            viewSum.setRowSum(rowSum);
            viewSum.setM1(m1);
            viewSum.setM2(m2);
            viewSum.setM3(m3);
            viewSum.setM4(m4);
            viewSum.setM5(m5);
            viewSum.setM6(m6);
            viewSum.setM7(m7);
            viewSum.setM8(m8);
            viewSum.setM9(m9);
            viewSum.setM10(m10);
            viewSum.setM11(m11);
            viewSum.setM12(m12);
            if(viewSum.getQudao()!=null&&viewSum.getProvice()!=null){
                list.add(0,viewSum);
            }
            m1=0;m2=0;m3=0;m4=0;m5=0;m6=0;m7=0;m8=0;m9=0;m10=0;m11=0;m12=0;rowSum=0;
            viewSum=null;
        }
        //把数据写入到Excel并返回文件路径和文件
        String filePath = ExcelUtils.exportCVS(list, qudaoProvinceTitle2018);
        json.put("sucessful", 1);//关闭进度条
        json.put("filePath", "/servlet/FileDownServlet?url=" + filePath);//文件下载,请求Servlet
        ResonseUtils.writeResponseByJson(response, json);
        return null;
    }
    //下载2018品种和省份
    @RequestMapping(value = "/download_2018productAndprovice.do")
    public JsonResult download_2018productAndprovice(HttpServletResponse response) {
        JSONObject json = new JSONObject();
        List<ProductProvinceData> plans = plansService.download_2018productAndprovice();
        //获取独立的渠道
        List<String> products = new ArrayList<String>();
        //获取独立的省份
        List<String> provices = new ArrayList<String>();
        for (ProductProvinceData s : plans) {
            if (!products.contains(s.getProduct())) {
                products.add(s.getProduct());
            }
            if (!provices.contains(s.getProvince())) {
                provices.add(s.getProvince());
            }
        }
        //准备下载数据
        List<ProductProvinceView> list = new ArrayList<ProductProvinceView>();
        //列汇总
        int m1=0,m2=0,m3=0,m4=0,m5=0,m6=0,m7=0,m8=0,m9=0,m10=0,m11=0,m12=0,rowSum=0;

        for (String q : products) {
            ProductProvinceView viewSum = new ProductProvinceView();
            for (String s : provices) {
                ProductProvinceView view = new ProductProvinceView();
                for (ProductProvinceData v : plans) {
                    if (q.equals(v.getProduct())) {
                        if (s.equals(v.getProvince())) {
                            if(view.getProduct() == null){
                                view.setProduct(v.getProduct());
                            }
                            if(view.getProvince() == null) {
                                view.setProvince(v.getProvince());
                            }
                            if(v.getMonth().equals("01")){view.setM1(v.getSumScount());}
                            if(v.getMonth().equals("02")){view.setM2(v.getSumScount());}
                            if(v.getMonth().equals("03")){view.setM3(v.getSumScount());}
                            if(v.getMonth().equals("04")){view.setM4(v.getSumScount());}
                            if(v.getMonth().equals("05")){view.setM5(v.getSumScount());}
                            if(v.getMonth().equals("06")){view.setM6(v.getSumScount());}
                            if(v.getMonth().equals("07")){view.setM7(v.getSumScount());}
                            if(v.getMonth().equals("08")){view.setM8(v.getSumScount());}
                            if(v.getMonth().equals("09")){view.setM9(v.getSumScount());}
                            if(v.getMonth().equals("10")){view.setM10(v.getSumScount());}
                            if(v.getMonth().equals("11")){view.setM11(v.getSumScount());}
                            if(v.getMonth().equals("12")){view.setM12(v.getSumScount());}
                        }
                    }
                }
                view.setRowSum(view.getM1()+view.getM2()+view.getM3()+view.getM4()+view.getM5()+view.getM6()+view.getM7()+view.getM8()+view.getM9()+view.getM10()+view.getM11()+view.getM12());
                if(view.getProvince()!=null&&view.getProvince()!=null){
                    list.add(view);
                    //列汇总
                    m1+=view.getM1(); m2+=view.getM2(); m3+=view.getM3(); m4+=view.getM4(); m5+=view.getM5(); m6+=view.getM6(); m7+=view.getM7(); m8+=view.getM8(); m9+=view.getM9(); m10+=view.getM10(); m11+=view.getM11(); m12+=view.getM12();
                    view=null;
                }
            }
            rowSum=m1+m2+m3+m4+m5+m6+m7+m8+m9+m10+m11+m12;
            viewSum.setProduct(q+"汇总");
            viewSum.setProvince("");
            viewSum.setRowSum(rowSum);
            viewSum.setM1(m1);
            viewSum.setM2(m2);
            viewSum.setM3(m3);
            viewSum.setM4(m4);
            viewSum.setM5(m5);
            viewSum.setM6(m6);
            viewSum.setM7(m7);
            viewSum.setM8(m8);
            viewSum.setM9(m9);
            viewSum.setM10(m10);
            viewSum.setM11(m11);
            viewSum.setM12(m12);
            if(viewSum.getProduct()!=null&&viewSum.getProvince()!=null){
                list.add(0,viewSum);
            }
            m1=0;m2=0;m3=0;m4=0;m5=0;m6=0;m7=0;m8=0;m9=0;m10=0;m11=0;m12=0;rowSum=0;
            viewSum=null;
        }
        //把数据写入到Excel并返回文件路径和文件
        String filePath = ExcelUtils.exportCVS(list, productProvinceTitle2018);
        json.put("sucessful", 1);//关闭进度条
        json.put("filePath", "/servlet/FileDownServlet?url=" + filePath);//文件下载,请求Servlet
        ResonseUtils.writeResponseByJson(response, json);
        return null;
    }
    //下载2018渠道和片区
    @RequestMapping(value = "/download_2018qudaoAndSpace.do")
    public JsonResult download_2018qudaoAndSpace(HttpServletResponse response) {
        JSONObject json = new JSONObject();
        List<QudaoSpaceData> plans = plansService.download_2018qudaoAndSpace();
        //获取独立的渠道
        List<String> qudaos = new ArrayList<String>();
        //获取独立的片区
        List<String> spaces = new ArrayList<String>();
        for (QudaoSpaceData s : plans) {
            if (!qudaos.contains(s.getQudao())) {
                qudaos.add(s.getQudao());
            }
            if (!spaces.contains(s.getSpace())) {
                spaces.add(s.getSpace());
            }
        }
        //准备下载数据
        List<QudaoSpaceView> list = new ArrayList<QudaoSpaceView>();
        //列汇总
        int m1=0,m2=0,m3=0,m4=0,m5=0,m6=0,m7=0,m8=0,m9=0,m10=0,m11=0,m12=0,rowSum=0;

        for (String q : qudaos) {
            QudaoSpaceView viewSum = new QudaoSpaceView();
            for (String s : spaces) {
                QudaoSpaceView view = new QudaoSpaceView();
                for (QudaoSpaceData v : plans) {
                    if (q.equals(v.getQudao())) {
                        if (s.equals(v.getSpace())) {
                            if(view.getQudao() == null){
                                view.setQudao(v.getQudao());
                            }
                            if(view.getSpace() == null) {
                                view.setSpace(v.getSpace());
                            }
                            if(view.getMgr() == null) {
                                view.setMgr(v.getMgr());
                            }
                            if(v.getMonth().equals("01")){view.setM1(v.getSumScount());}
                            if(v.getMonth().equals("02")){view.setM2(v.getSumScount());}
                            if(v.getMonth().equals("03")){view.setM3(v.getSumScount());}
                            if(v.getMonth().equals("04")){view.setM4(v.getSumScount());}
                            if(v.getMonth().equals("05")){view.setM5(v.getSumScount());}
                            if(v.getMonth().equals("06")){view.setM6(v.getSumScount());}
                            if(v.getMonth().equals("07")){view.setM7(v.getSumScount());}
                            if(v.getMonth().equals("08")){view.setM8(v.getSumScount());}
                            if(v.getMonth().equals("09")){view.setM9(v.getSumScount());}
                            if(v.getMonth().equals("10")){view.setM10(v.getSumScount());}
                            if(v.getMonth().equals("11")){view.setM11(v.getSumScount());}
                            if(v.getMonth().equals("12")){view.setM12(v.getSumScount());}
                        }
                    }
                }
                view.setRowSum(view.getM1()+view.getM2()+view.getM3()+view.getM4()+view.getM5()+view.getM6()+view.getM7()+view.getM8()+view.getM9()+view.getM10()+view.getM11()+view.getM12());
                if(view.getQudao()!=null&&view.getSpace()!=null){
                    list.add(view);
                    //列汇总
                    m1+=view.getM1(); m2+=view.getM2(); m3+=view.getM3(); m4+=view.getM4(); m5+=view.getM5(); m6+=view.getM6(); m7+=view.getM7(); m8+=view.getM8(); m9+=view.getM9(); m10+=view.getM10(); m11+=view.getM11(); m12+=view.getM12();
                    view = null;
                }
            }
            rowSum=m1+m2+m3+m4+m5+m6+m7+m8+m9+m10+m11+m12;
            viewSum.setQudao(q+"汇总");
            viewSum.setSpace("");
            viewSum.setMgr("");
            viewSum.setRowSum(rowSum);
            viewSum.setM1(m1);
            viewSum.setM2(m2);
            viewSum.setM3(m3);
            viewSum.setM4(m4);
            viewSum.setM5(m5);
            viewSum.setM6(m6);
            viewSum.setM7(m7);
            viewSum.setM8(m8);
            viewSum.setM9(m9);
            viewSum.setM10(m10);
            viewSum.setM11(m11);
            viewSum.setM12(m12);
            if(viewSum.getQudao()!=null&&viewSum.getSpace()!=null){
                list.add(0,viewSum);
            }
            m1=0;m2=0;m3=0;m4=0;m5=0;m6=0;m7=0;m8=0;m9=0;m10=0;m11=0;m12=0;rowSum=0;
            viewSum = null;
        }
        //把数据写入到Excel并返回文件路径和文件
        String filePath = ExcelUtils.exportCVS(list, qudaoSpaceTitle2018);
        json.put("sucessful", 1);//关闭进度条
        json.put("filePath", "/servlet/FileDownServlet?url=" + filePath);//文件下载,请求Servlet
        ResonseUtils.writeResponseByJson(response, json);
        return null;
    }
    //下载2018品种和片区
    @RequestMapping(value = "/download_2018productAndSpace.do")
    public JsonResult download_2018productAndSpace(HttpServletResponse response) {
        JSONObject json = new JSONObject();
        List<ProductSpaceData> plans = plansService.download_2018productAndSpace();
        //获取独立的品种
        List<String> products = new ArrayList<String>();
        //获取独立的片区
        List<String> spaces = new ArrayList<String>();
        for (ProductSpaceData s : plans) {
            if (!products.contains(s.getProduct())) {
                products.add(s.getProduct());
            }
            if (!spaces.contains(s.getSpace())) {
                spaces.add(s.getSpace());
            }
        }
        //准备下载数据
        List<ProductSpaceView> list = new ArrayList<ProductSpaceView>();
        //列汇总
        int m1=0,m2=0,m3=0,m4=0,m5=0,m6=0,m7=0,m8=0,m9=0,m10=0,m11=0,m12=0,rowSum=0;

        for (String q : products) {
            ProductSpaceView viewSum = new ProductSpaceView();
            for (String s : spaces) {
                ProductSpaceView view = new ProductSpaceView();
                for (ProductSpaceData v : plans) {
                    if (q.equals(v.getProduct())) {
                        if (s.equals(v.getSpace())) {
                            if(view.getProduct() == null){
                                view.setProduct(v.getProduct());
                            }
                            if(view.getSpace() == null) {
                                view.setSpace(v.getSpace());
                            }
                            if(view.getMgr() == null) {
                                view.setMgr(v.getMgr());
                            }
                            if(v.getMonth().equals("01")){view.setM1(v.getSumScount());}
                            if(v.getMonth().equals("02")){view.setM2(v.getSumScount());}
                            if(v.getMonth().equals("03")){view.setM3(v.getSumScount());}
                            if(v.getMonth().equals("04")){view.setM4(v.getSumScount());}
                            if(v.getMonth().equals("05")){view.setM5(v.getSumScount());}
                            if(v.getMonth().equals("06")){view.setM6(v.getSumScount());}
                            if(v.getMonth().equals("07")){view.setM7(v.getSumScount());}
                            if(v.getMonth().equals("08")){view.setM8(v.getSumScount());}
                            if(v.getMonth().equals("09")){view.setM9(v.getSumScount());}
                            if(v.getMonth().equals("10")){view.setM10(v.getSumScount());}
                            if(v.getMonth().equals("11")){view.setM11(v.getSumScount());}
                            if(v.getMonth().equals("12")){view.setM12(v.getSumScount());}
                        }
                    }
                }
                view.setRowSum(view.getM1()+view.getM2()+view.getM3()+view.getM4()+view.getM5()+view.getM6()+view.getM7()+view.getM8()+view.getM9()+view.getM10()+view.getM11()+view.getM12());
                if(view.getProduct()!=null&&view.getSpace()!=null){
                    list.add(view);
                    //列汇总
                    m1+=view.getM1(); m2+=view.getM2(); m3+=view.getM3(); m4+=view.getM4(); m5+=view.getM5(); m6+=view.getM6(); m7+=view.getM7(); m8+=view.getM8(); m9+=view.getM9(); m10+=view.getM10(); m11+=view.getM11(); m12+=view.getM12();
                    view = null;
                }
            }
            rowSum=m1+m2+m3+m4+m5+m6+m7+m8+m9+m10+m11+m12;
            viewSum.setProduct(q+"汇总");
            viewSum.setSpace("");
            viewSum.setMgr("");
            viewSum.setRowSum(rowSum);
            viewSum.setM1(m1);
            viewSum.setM2(m2);
            viewSum.setM3(m3);
            viewSum.setM4(m4);
            viewSum.setM5(m5);
            viewSum.setM6(m6);
            viewSum.setM7(m7);
            viewSum.setM8(m8);
            viewSum.setM9(m9);
            viewSum.setM10(m10);
            viewSum.setM11(m11);
            viewSum.setM12(m12);
            if(viewSum.getProduct()!=null&&viewSum.getSpace()!=null){
                list.add(0,viewSum);
            }
            m1=0;m2=0;m3=0;m4=0;m5=0;m6=0;m7=0;m8=0;m9=0;m10=0;m11=0;m12=0;rowSum=0;
            viewSum = null;
        }
        //把数据写入到Excel并返回文件路径和文件
        String filePath = ExcelUtils.exportCVS(list, productSpaceTitle2018);
        json.put("sucessful", 1);//关闭进度条
        json.put("filePath", "/servlet/FileDownServlet?url=" + filePath);//文件下载,请求Servlet
        ResonseUtils.writeResponseByJson(response, json);
        return null;
    }

    //下载2017渠道和省份
    @RequestMapping(value = "/download_2017qudaoAndProvice.do")
    public JsonResult download_2017qudaoAndProvice(HttpServletResponse response) {
        JSONObject json = new JSONObject();
        List<QudaoProvinceData> plans = plansService.download_2017qudaoAndProvice();
        //获取独立的渠道
        List<String> qudaos = new ArrayList<String>();
        //获取独立的省份
        List<String> provices = new ArrayList<String>();
        for (QudaoProvinceData s : plans) {
            if (!qudaos.contains(s.getQudao())) {
                qudaos.add(s.getQudao());
            }
            if (!provices.contains(s.getProvince())) {
                provices.add(s.getProvince());
            }
        }
        //准备下载数据
        List<QudaoProvinceView> list = new ArrayList<QudaoProvinceView>();
        //列汇总
        int m1=0,m2=0,m3=0,m4=0,m5=0,m6=0,m7=0,m8=0,m9=0,m10=0,m11=0,m12=0,rowSum=0;

        for (String q : qudaos) {
            QudaoProvinceView viewSum = new QudaoProvinceView();
            for (String s : provices) {
                QudaoProvinceView view = new QudaoProvinceView();
                for (QudaoProvinceData v : plans) {
                    if (q.equals(v.getQudao())) {
                        if (s.equals(v.getProvince())) {
                            if(view.getQudao() == null){
                                view.setQudao(v.getQudao());
                            }
                            if(view.getProvice() == null) {
                                view.setProvice(v.getProvince());
                            }
                            if(v.getMonth().equals("01")){view.setM1(v.getSumScount());}
                            if(v.getMonth().equals("02")){view.setM2(v.getSumScount());}
                            if(v.getMonth().equals("03")){view.setM3(v.getSumScount());}
                            if(v.getMonth().equals("04")){view.setM4(v.getSumScount());}
                            if(v.getMonth().equals("05")){view.setM5(v.getSumScount());}
                            if(v.getMonth().equals("06")){view.setM6(v.getSumScount());}
                            if(v.getMonth().equals("07")){view.setM7(v.getSumScount());}
                            if(v.getMonth().equals("08")){view.setM8(v.getSumScount());}
                            if(v.getMonth().equals("09")){view.setM9(v.getSumScount());}
                            if(v.getMonth().equals("10")){view.setM10(v.getSumScount());}
                            if(v.getMonth().equals("11")){view.setM11(v.getSumScount());}
                            if(v.getMonth().equals("12")){view.setM12(v.getSumScount());}
                        }
                    }
                }
                view.setRowSum(view.getM1()+view.getM2()+view.getM3()+view.getM4()+view.getM5()+view.getM6()+view.getM7()+view.getM8()+view.getM9()+view.getM10()+view.getM11()+view.getM12());
                if(view.getQudao()!=null&&view.getProvice()!=null){
                    list.add(view);
                    //列汇总
                    m1+=view.getM1(); m2+=view.getM2(); m3+=view.getM3(); m4+=view.getM4(); m5+=view.getM5(); m6+=view.getM6(); m7+=view.getM7(); m8+=view.getM8(); m9+=view.getM9(); m10+=view.getM10(); m11+=view.getM11(); m12+=view.getM12();
                    view=null;
                }
            }
            rowSum=m1+m2+m3+m4+m5+m6+m7+m8+m9+m10+m11+m12;
            viewSum.setQudao(q+"汇总");
            viewSum.setProvice("");
            viewSum.setRowSum(rowSum);
            viewSum.setM1(m1);
            viewSum.setM2(m2);
            viewSum.setM3(m3);
            viewSum.setM4(m4);
            viewSum.setM5(m5);
            viewSum.setM6(m6);
            viewSum.setM7(m7);
            viewSum.setM8(m8);
            viewSum.setM9(m9);
            viewSum.setM10(m10);
            viewSum.setM11(m11);
            viewSum.setM12(m12);
            if(viewSum.getQudao()!=null&&viewSum.getProvice()!=null){
                list.add(0,viewSum);
            }
            m1=0;m2=0;m3=0;m4=0;m5=0;m6=0;m7=0;m8=0;m9=0;m10=0;m11=0;m12=0;rowSum=0;
            viewSum=null;
        }
        //把数据写入到Excel并返回文件路径和文件
        String filePath = ExcelUtils.exportCVS(list, qudaoProvinceTitle2017);
        json.put("sucessful", 1);//关闭进度条
        json.put("filePath", "/servlet/FileDownServlet?url=" + filePath);//文件下载,请求Servlet
        ResonseUtils.writeResponseByJson(response, json);
        return null;
    }
    //下载2017品种和省份
    @RequestMapping(value = "/download_2017productAndprovice.do")
    public JsonResult download_2017productAndprovice(HttpServletResponse response) {
        JSONObject json = new JSONObject();
        List<ProductProvinceData> plans = plansService.download_2017productAndprovice();
        //获取独立的渠道
        List<String> products = new ArrayList<String>();
        //获取独立的省份
        List<String> provices = new ArrayList<String>();
        for (ProductProvinceData s : plans) {
            if (!products.contains(s.getProduct())) {
                products.add(s.getProduct());
            }
            if (!provices.contains(s.getProvince())) {
                provices.add(s.getProvince());
            }
        }
        //准备下载数据
        List<ProductProvinceView> list = new ArrayList<ProductProvinceView>();
        //列汇总
        int m1=0,m2=0,m3=0,m4=0,m5=0,m6=0,m7=0,m8=0,m9=0,m10=0,m11=0,m12=0,rowSum=0;

        for (String q : products) {
            ProductProvinceView viewSum = new ProductProvinceView();
            for (String s : provices) {
                ProductProvinceView view = new ProductProvinceView();
                for (ProductProvinceData v : plans) {
                    if (q.equals(v.getProduct())) {
                        if (s.equals(v.getProvince())) {
                            if(view.getProduct() == null){
                                view.setProduct(v.getProduct());
                            }
                            if(view.getProvince() == null) {
                                view.setProvince(v.getProvince());
                            }
                            if(v.getMonth().equals("01")){view.setM1(v.getSumScount());}
                            if(v.getMonth().equals("02")){view.setM2(v.getSumScount());}
                            if(v.getMonth().equals("03")){view.setM3(v.getSumScount());}
                            if(v.getMonth().equals("04")){view.setM4(v.getSumScount());}
                            if(v.getMonth().equals("05")){view.setM5(v.getSumScount());}
                            if(v.getMonth().equals("06")){view.setM6(v.getSumScount());}
                            if(v.getMonth().equals("07")){view.setM7(v.getSumScount());}
                            if(v.getMonth().equals("08")){view.setM8(v.getSumScount());}
                            if(v.getMonth().equals("09")){view.setM9(v.getSumScount());}
                            if(v.getMonth().equals("10")){view.setM10(v.getSumScount());}
                            if(v.getMonth().equals("11")){view.setM11(v.getSumScount());}
                            if(v.getMonth().equals("12")){view.setM12(v.getSumScount());}
                        }
                    }
                }
                view.setRowSum(view.getM1()+view.getM2()+view.getM3()+view.getM4()+view.getM5()+view.getM6()+view.getM7()+view.getM8()+view.getM9()+view.getM10()+view.getM11()+view.getM12());
                if(view.getProvince()!=null&&view.getProvince()!=null){
                    list.add(view);
                    //列汇总
                    m1+=view.getM1(); m2+=view.getM2(); m3+=view.getM3(); m4+=view.getM4(); m5+=view.getM5(); m6+=view.getM6(); m7+=view.getM7(); m8+=view.getM8(); m9+=view.getM9(); m10+=view.getM10(); m11+=view.getM11(); m12+=view.getM12();
                    view=null;
                }
            }
            rowSum=m1+m2+m3+m4+m5+m6+m7+m8+m9+m10+m11+m12;
            viewSum.setProduct(q+"汇总");
            viewSum.setProvince("");
            viewSum.setRowSum(rowSum);
            viewSum.setM1(m1);
            viewSum.setM2(m2);
            viewSum.setM3(m3);
            viewSum.setM4(m4);
            viewSum.setM5(m5);
            viewSum.setM6(m6);
            viewSum.setM7(m7);
            viewSum.setM8(m8);
            viewSum.setM9(m9);
            viewSum.setM10(m10);
            viewSum.setM11(m11);
            viewSum.setM12(m12);
            if(viewSum.getProduct()!=null&&viewSum.getProvince()!=null){
                list.add(0,viewSum);
            }
            m1=0;m2=0;m3=0;m4=0;m5=0;m6=0;m7=0;m8=0;m9=0;m10=0;m11=0;m12=0;rowSum=0;
            viewSum=null;
        }
        //把数据写入到Excel并返回文件路径和文件
        String filePath = ExcelUtils.exportCVS(list, productProvinceTitle2017);
        json.put("sucessful", 1);//关闭进度条
        json.put("filePath", "/servlet/FileDownServlet?url=" + filePath);//文件下载,请求Servlet
        ResonseUtils.writeResponseByJson(response, json);
        return null;
    }
    //下载2017渠道和片区
    @RequestMapping(value = "/download_2017qudaoAndSpace.do")
    public JsonResult download_2017qudaoAndSpace(HttpServletResponse response) {
        JSONObject json = new JSONObject();
        List<QudaoSpaceData> plans = plansService.download_2017qudaoAndSpace();
        //获取独立的渠道
        List<String> qudaos = new ArrayList<String>();
        //获取独立的片区
        List<String> spaces = new ArrayList<String>();
        for (QudaoSpaceData s : plans) {
            if (!qudaos.contains(s.getQudao())) {
                qudaos.add(s.getQudao());
            }
            if (!spaces.contains(s.getSpace())) {
                spaces.add(s.getSpace());
            }
        }
        //准备下载数据
        List<QudaoSpaceView> list = new ArrayList<QudaoSpaceView>();
        //列汇总
        int m1=0,m2=0,m3=0,m4=0,m5=0,m6=0,m7=0,m8=0,m9=0,m10=0,m11=0,m12=0,rowSum=0;

        for (String q : qudaos) {
            QudaoSpaceView viewSum = new QudaoSpaceView();
            for (String s : spaces) {
                QudaoSpaceView view = new QudaoSpaceView();
                for (QudaoSpaceData v : plans) {
                    if (q.equals(v.getQudao())) {
                        if (s.equals(v.getSpace())) {
                            if(view.getQudao() == null){
                                view.setQudao(v.getQudao());
                            }
                            if(view.getSpace() == null) {
                                view.setSpace(v.getSpace());
                            }
                            if(view.getMgr() == null) {
                                view.setMgr(v.getMgr());
                            }
                            if(v.getMonth().equals("01")){view.setM1(v.getSumScount());}
                            if(v.getMonth().equals("02")){view.setM2(v.getSumScount());}
                            if(v.getMonth().equals("03")){view.setM3(v.getSumScount());}
                            if(v.getMonth().equals("04")){view.setM4(v.getSumScount());}
                            if(v.getMonth().equals("05")){view.setM5(v.getSumScount());}
                            if(v.getMonth().equals("06")){view.setM6(v.getSumScount());}
                            if(v.getMonth().equals("07")){view.setM7(v.getSumScount());}
                            if(v.getMonth().equals("08")){view.setM8(v.getSumScount());}
                            if(v.getMonth().equals("09")){view.setM9(v.getSumScount());}
                            if(v.getMonth().equals("10")){view.setM10(v.getSumScount());}
                            if(v.getMonth().equals("11")){view.setM11(v.getSumScount());}
                            if(v.getMonth().equals("12")){view.setM12(v.getSumScount());}
                        }
                    }
                }
                view.setRowSum(view.getM1()+view.getM2()+view.getM3()+view.getM4()+view.getM5()+view.getM6()+view.getM7()+view.getM8()+view.getM9()+view.getM10()+view.getM11()+view.getM12());
                if(view.getQudao()!=null&&view.getSpace()!=null){
                    list.add(view);
                    //列汇总
                    m1+=view.getM1(); m2+=view.getM2(); m3+=view.getM3(); m4+=view.getM4(); m5+=view.getM5(); m6+=view.getM6(); m7+=view.getM7(); m8+=view.getM8(); m9+=view.getM9(); m10+=view.getM10(); m11+=view.getM11(); m12+=view.getM12();
                    view = null;
                }
            }
            rowSum=m1+m2+m3+m4+m5+m6+m7+m8+m9+m10+m11+m12;
            viewSum.setQudao(q+"汇总");
            viewSum.setSpace("");
            viewSum.setMgr("");
            viewSum.setRowSum(rowSum);
            viewSum.setM1(m1);
            viewSum.setM2(m2);
            viewSum.setM3(m3);
            viewSum.setM4(m4);
            viewSum.setM5(m5);
            viewSum.setM6(m6);
            viewSum.setM7(m7);
            viewSum.setM8(m8);
            viewSum.setM9(m9);
            viewSum.setM10(m10);
            viewSum.setM11(m11);
            viewSum.setM12(m12);
            if(viewSum.getQudao()!=null&&viewSum.getSpace()!=null){
                list.add(0,viewSum);
            }
            m1=0;m2=0;m3=0;m4=0;m5=0;m6=0;m7=0;m8=0;m9=0;m10=0;m11=0;m12=0;rowSum=0;
            viewSum = null;
        }
        //把数据写入到Excel并返回文件路径和文件
        String filePath = ExcelUtils.exportCVS(list, qudaoSpaceTitle2017);
        json.put("sucessful", 1);//关闭进度条
        json.put("filePath", "/servlet/FileDownServlet?url=" + filePath);//文件下载,请求Servlet
        ResonseUtils.writeResponseByJson(response, json);
        return null;
    }
    //下载2017品种和片区
    @RequestMapping(value = "/download_2017productAndSpace.do")
    public JsonResult download_2017productAndSpace(HttpServletResponse response) {
        JSONObject json = new JSONObject();
        List<ProductSpaceData> plans = plansService.download_2017productAndSpace();
        //获取独立的品种
        List<String> products = new ArrayList<String>();
        //获取独立的片区
        List<String> spaces = new ArrayList<String>();
        for (ProductSpaceData s : plans) {
            if (!products.contains(s.getProduct())) {
                products.add(s.getProduct());
            }
            if (!spaces.contains(s.getSpace())) {
                spaces.add(s.getSpace());
            }
        }
        //准备下载数据
        List<ProductSpaceView> list = new ArrayList<ProductSpaceView>();
        //列汇总
        int m1=0,m2=0,m3=0,m4=0,m5=0,m6=0,m7=0,m8=0,m9=0,m10=0,m11=0,m12=0,rowSum=0;

        for (String q : products) {
            ProductSpaceView viewSum = new ProductSpaceView();
            for (String s : spaces) {
                ProductSpaceView view = new ProductSpaceView();
                for (ProductSpaceData v : plans) {
                    if (q.equals(v.getProduct())) {
                        if (s.equals(v.getSpace())) {
                            if(view.getProduct() == null){
                                view.setProduct(v.getProduct());
                            }
                            if(view.getSpace() == null) {
                                view.setSpace(v.getSpace());
                            }
                            if(view.getMgr() == null) {
                                view.setMgr(v.getMgr());
                            }
                            if(v.getMonth().equals("01")){view.setM1(v.getSumScount());}
                            if(v.getMonth().equals("02")){view.setM2(v.getSumScount());}
                            if(v.getMonth().equals("03")){view.setM3(v.getSumScount());}
                            if(v.getMonth().equals("04")){view.setM4(v.getSumScount());}
                            if(v.getMonth().equals("05")){view.setM5(v.getSumScount());}
                            if(v.getMonth().equals("06")){view.setM6(v.getSumScount());}
                            if(v.getMonth().equals("07")){view.setM7(v.getSumScount());}
                            if(v.getMonth().equals("08")){view.setM8(v.getSumScount());}
                            if(v.getMonth().equals("09")){view.setM9(v.getSumScount());}
                            if(v.getMonth().equals("10")){view.setM10(v.getSumScount());}
                            if(v.getMonth().equals("11")){view.setM11(v.getSumScount());}
                            if(v.getMonth().equals("12")){view.setM12(v.getSumScount());}
                        }
                    }
                }
                view.setRowSum(view.getM1()+view.getM2()+view.getM3()+view.getM4()+view.getM5()+view.getM6()+view.getM7()+view.getM8()+view.getM9()+view.getM10()+view.getM11()+view.getM12());
                if(view.getProduct()!=null&&view.getSpace()!=null){
                    list.add(view);
                    //列汇总
                    m1+=view.getM1(); m2+=view.getM2(); m3+=view.getM3(); m4+=view.getM4(); m5+=view.getM5(); m6+=view.getM6(); m7+=view.getM7(); m8+=view.getM8(); m9+=view.getM9(); m10+=view.getM10(); m11+=view.getM11(); m12+=view.getM12();
                    view = null;
                }
            }
            rowSum=m1+m2+m3+m4+m5+m6+m7+m8+m9+m10+m11+m12;
            viewSum.setProduct(q+"汇总");
            viewSum.setSpace("");
            viewSum.setMgr("");
            viewSum.setRowSum(rowSum);
            viewSum.setM1(m1);
            viewSum.setM2(m2);
            viewSum.setM3(m3);
            viewSum.setM4(m4);
            viewSum.setM5(m5);
            viewSum.setM6(m6);
            viewSum.setM7(m7);
            viewSum.setM8(m8);
            viewSum.setM9(m9);
            viewSum.setM10(m10);
            viewSum.setM11(m11);
            viewSum.setM12(m12);
            if(viewSum.getProduct()!=null&&viewSum.getSpace()!=null){
                list.add(0,viewSum);
            }
            m1=0;m2=0;m3=0;m4=0;m5=0;m6=0;m7=0;m8=0;m9=0;m10=0;m11=0;m12=0;rowSum=0;
            viewSum = null;
        }
        //把数据写入到Excel并返回文件路径和文件
        String filePath = ExcelUtils.exportCVS(list, productSpaceTitle2017);
        json.put("sucessful", 1);//关闭进度条
        json.put("filePath", "/servlet/FileDownServlet?url=" + filePath);//文件下载,请求Servlet
        ResonseUtils.writeResponseByJson(response, json);
        return null;
    }


    //查询16、17年纯销、销售汇总折合量
    @RequestMapping(value = "/selectOldYearsPlansAllSum.do")
    public JsonResult selectOldYearsPlansAllSum(HttpServletResponse response) {
        JSONObject json = new JSONObject();
        Integer count2016cx = plansService.selectOldYear2016CxPlansAllSum();
        Integer count2016xs = plansService.selectOldYear2016XsPlansAllSum();
        Integer count2017cx = plansService.selectOldYear2017CxPlansAllSum();
        Integer count2017xs = plansService.selectOldYear2017XsPlansAllSum();
        json.put("count2016cx", count2016cx);
        json.put("count2016xs", count2016xs);
        json.put("count2017cx", count2017cx);
        json.put("count2017xs", count2017xs);
        ResonseUtils.writeResponseByJson(response, json);
        return null;
    }

    //查询新开发终端
    @RequestMapping(value = "/selectNewTerminals.do")
    public JsonResult selectNewTerminals(HttpServletResponse response) {
        JSONObject json = new JSONObject();
        //所有的保有终端
        List<TerminalPlans> oldTerminals = plansService.selectOldTerminals();
        //也许是新终端
        List<TerminalPlans> maybeNewTerminals = plansService.selectMaybeNewTerminals();
        maybeNewTerminals.removeAll(oldTerminals);//差集
        json.put("count", maybeNewTerminals.size());
        int sum = 0;
        for (TerminalPlans s : maybeNewTerminals) {
            sum += s.getSumScount();
        }
        json.put("sum", sum);
        ResonseUtils.writeResponseByJson(response, json);
        return null;
    }

    //查询自然流向
    @RequestMapping(value = "/selectNatural.do")
    public JsonResult selectNatural(HttpServletResponse response) {
        JSONObject json = new JSONObject();
        Integer count = plansService.selectNatural() == null ? 0 : plansService.selectNatural();
        Integer countReal = plansService.selectRealNatural() == null ? 0 : plansService.selectRealNatural();
        Integer waitDealCount = count - countReal;
        json.put("count", count);
        json.put("countReal", countReal);
        json.put("waitDealCount", waitDealCount);
        ResonseUtils.writeResponseByJson(response, json);
        return null;
    }

    //查询2018有效客户、保有终端
    @RequestMapping(value = "/selectClientCount.do")
    public JsonResult selectClientCount(HttpServletResponse response) {
        JSONObject json = new JSONObject();
        Integer count = plansService.selectClientCount() == null ? 0 : plansService.selectClientCount();
        json.put("count", count);
        Integer terminalCount = plansService.selectTerminalCount() == null ? 0 : plansService.selectTerminalCount();
        json.put("terminalCount", terminalCount);
        ResonseUtils.writeResponseByJson(response, json);
        return null;
    }

    //查询2018有效终端
    @RequestMapping(value = "/selectTerminalCount.do")
    public JsonResult selectTerminalCount(HttpServletResponse response) {
        JSONObject json = new JSONObject();
        Integer count = plansService.selectTerminalCount() == null ? 0 : plansService.selectTerminalCount();
        json.put("count", count);
        ResonseUtils.writeResponseByJson(response, json);
        return null;
    }

    //查询2018流向情况 主页饼图
    @RequestMapping(value = "/select2018CxScountBingTu.do")
    public JsonResult select2018CxScountBingTu(HttpServletResponse response) {
        JSONObject json = new JSONObject();
        List<Plans> list = plansService.select2018RxCxScount();
        for (Plans p : list) {
            json.put("Rx" + p.getProduct(), p.getSumScount());
        }
        List<Plans> listOTC = plansService.select2018OTCCxScount();
        for (Plans p : listOTC) {
            json.put("OTC" + p.getProduct(), p.getSumScount());
        }
        ResonseUtils.writeResponseByJson(response, json);
        return null;
    }

    //查询按省份分组，2018流向情况 首页进度条
    @RequestMapping(value = "/selectProvince2018CxScount.do")
    public JsonResult selectProvince2018CxScount(HttpServletResponse response) {
        JSONObject json = new JSONObject();
        List<Plans> list = plansService.selectProvince2018CxScount();
        Plans p = list.get(0);
        json.put("count", p.getSumScount() == null ? 0 : Float.parseFloat(p.getSumScount()) * 3.5);
        json.put("list", list);
        ResonseUtils.writeResponseByJson(response, json);
        return null;
    }
    //查询按大区分组，2018流向情况 首页进度条
    @RequestMapping(value = "/selectBigSpace2018CxScount.do")
    public JsonResult selectBigSpace2018CxScount(HttpServletResponse response) {
        JSONObject json = new JSONObject();
        List<Plans> list = plansService.selectBigSpace2018CxScount();
        Plans p = list.get(0);
        json.put("count", p.getSumScount() == null ? 0 : Float.parseFloat(p.getSumScount()) * 3.5);
        json.put("list", list);
        ResonseUtils.writeResponseByJson(response, json);
        return null;
    }
    //查询按片区分组，2018流向情况 首页进度条
    @RequestMapping(value = "/selectSpace2018CxScount.do")
    public JsonResult selectSpace2018CxScount(HttpServletResponse response) {
        JSONObject json = new JSONObject();
        List<Plans> list = plansService.selectSpace2018CxScount();
        Plans p = list.get(0);
        json.put("count", p.getSumScount() == null ? 0 : Float.parseFloat(p.getSumScount()) * 3.5);
        json.put("list", list);
        ResonseUtils.writeResponseByJson(response, json);
        return null;
    }

    //查询2018流向情况
    @RequestMapping(value = "/select2018RxCxScount.do")
    public JsonResult select2018RxCxScount(HttpServletResponse response) {
        JSONObject json = new JSONObject();
        List<Plans> list = plansService.select2018RxCxScount();
        json.put("list", list);
        ResonseUtils.writeResponseByJson(response, json);
        return null;
    }

    //查询流向 plans_query.jsp
    @RequestMapping(value = "/selectPlans.do")
    public JsonResult selectPlans(HttpServletResponse response,String stime,String etime,String client,
                                  String terminal,String[] product,String[] policy_status,String[] jieshuang_status,String ids) {
        Map<String,Object> params = new HashMap<String, Object>();
        if(stime != null && !"".equals(stime.trim())){
            params.put("stime",stime);
        }
        if(etime != null && !"".equals(etime.trim())){
            params.put("etime",etime);
        }
        if(client != null && !"".equals(client.trim())){
            params.put("client",client);
        }
        if(terminal != null && !"".equals(terminal.trim())){
            params.put("terminal",terminal);
        }
        if(product != null && product.length >=1){
            params.put("product",product);
        }
        if(policy_status != null && policy_status.length >=1){
            params.put("policy_status",policy_status);
        }
        if(jieshuang_status != null && jieshuang_status.length >=1){
            params.put("jieshuang_status",jieshuang_status);
        }
        if(ids != null && ids.length() >=1){
            String[] strs = ids.split(" ");
            params.put("ids",strs);
        }
        JSONObject json = new JSONObject();
        List<PlansView> list = plansService.selectPlans(params);
        json.put("list", list);
        ResonseUtils.writeResponseByJson(response, json);
        return null;
    }

    @RequestMapping(value = "/select2018RxCxScountCurrentMonth.do")
    public JsonResult select2018RxCxScountCurrentMonth(HttpServletResponse response) {
        JSONObject json = new JSONObject();
        List<Plans> list = plansService.select2018RxCxScountCurrentMonth();
        json.put("list", list);
        ResonseUtils.writeResponseByJson(response, json);
        return null;
    }

    @RequestMapping(value = "/select2018OTCCxScount.do")
    public JsonResult select2018OTCCxScount(HttpServletResponse response) {
        JSONObject json = new JSONObject();
        List<Plans> list = plansService.select2018OTCCxScount();
        json.put("list", list);
        ResonseUtils.writeResponseByJson(response, json);
        return null;
    }

    @RequestMapping(value = "/select2018OTCCxScountCurrentMonth.do")
    public JsonResult select2018OTCCxScountCurrentMonth(HttpServletResponse response) {
        JSONObject json = new JSONObject();
        List<Plans> list = plansService.select2018OTCCxScountCurrentMonth();
        json.put("list", list);
        ResonseUtils.writeResponseByJson(response, json);
        return null;
    }

    @RequestMapping(value = "/selectCx2018Sum.do")
    public JsonResult selectCx2018Sum(HttpServletResponse response) {
        JSONObject json = new JSONObject();
        List<FeiYong> list = plansService.selectCx2018Sum();
        json.put("list", list);
        ResonseUtils.writeResponseByJson(response, json);
        return null;
    }

    @RequestMapping(value = "/selectXs2018Sum.do")
    public JsonResult selectXs2018Sum(HttpServletResponse response) {
        JSONObject json = new JSONObject();
        List<FeiYong> list = plansService.selectXs2018Sum();
        json.put("list", list);
        ResonseUtils.writeResponseByJson(response, json);
        return null;
    }

    @RequestMapping(value = "/selectCx2017Sum.do")
    public JsonResult selectCx2017Sum(HttpServletResponse response) {
        JSONObject json = new JSONObject();
        List<FeiYong> list = plansService.selectCx2017Sum();
        json.put("list", list);
        ResonseUtils.writeResponseByJson(response, json);
        return null;
    }

    @RequestMapping(value = "/selectXs2017Sum.do")
    public JsonResult selectXs2017Sum(HttpServletResponse response) {
        JSONObject json = new JSONObject();
        List<FeiYong> list = plansService.selectXs2017Sum();
        json.put("list", list);
        ResonseUtils.writeResponseByJson(response, json);
        return null;
    }

    @RequestMapping(value = "/selectCx2018Space.do")
    public JsonResult selectCx2018Space(HttpServletResponse response) {
        JSONObject json = new JSONObject();
        List<FeiYong> list = plansService.selectCx2018Space();
        json.put("list", list);
        ResonseUtils.writeResponseByJson(response, json);
        return null;
    }

    @RequestMapping(value = "/selectXs2018Space.do")
    public JsonResult selectXs2018Space(HttpServletResponse response) {
        JSONObject json = new JSONObject();
        List<FeiYong> list = plansService.selectXs2018Space();
        json.put("list", list);
        ResonseUtils.writeResponseByJson(response, json);
        return null;
    }

    @RequestMapping(value = "/selectCx2017Space.do")
    public JsonResult selectCx2017Space(HttpServletResponse response) {
        JSONObject json = new JSONObject();
        List<FeiYong> list = plansService.selectCx2017Space();
        json.put("list", list);
        ResonseUtils.writeResponseByJson(response, json);
        return null;
    }

    @RequestMapping(value = "/selectXs2017Space.do")
    public JsonResult selectXs2017Space(HttpServletRequest request, HttpServletResponse response) {
        System.out.println("请求：type="+request.getMethod());
    	JSONObject json = new JSONObject();
        List<FeiYong> list = plansService.selectXs2017Space();
        json.put("list", list);
        ResonseUtils.writeResponseByJson(response, json);
        return null;
    }
    
    /***
	 * 展示UI页面 储存过程下载流向
	 * @return
	 */
	@RequestMapping(value="download_plansUI")
	public String download_plans() {
		return "download_plans";
	}
	/***
	 * 展示UI页面 储存过程下载流向报表
	 * @return
	 */
	@RequestMapping(value="download_reportUI")
	public String download_report() {
		return "download_report";
	}
}
